459 lines
16 KiB
C#
459 lines
16 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Web;
|
|
using System.Web.Mvc;
|
|
using BeWo.Data.Access;
|
|
using BeWo.Data.Entities;
|
|
using BeWo.Service.ServiceImplementations;
|
|
using BeWoPlanerMobil.Service;
|
|
using BS.Shared;
|
|
using log4net.Core;
|
|
|
|
namespace BeWoPlanerMobil.Controllers
|
|
{
|
|
public class ChatController : Controller
|
|
{
|
|
//
|
|
// GET: /ChatToken/
|
|
|
|
//public ActionResult Index()
|
|
//{
|
|
// return View();
|
|
//}
|
|
|
|
public string Index()
|
|
{
|
|
return "Das ist die <b>Default</b> Aktion... Sie haben hier nix verloren.";
|
|
}
|
|
|
|
public JsonResult LoginToken(string benutzername , string passwort, string kundennummer,string typ)
|
|
{
|
|
// lese hier die daten aus dem header aus
|
|
//var x = HttpUtility.HtmlEncode("Benutzer: "+benutzername+" / "+ "Passwort: "+passwort +" / "+"Kundennummer: "+kundennummer);
|
|
|
|
|
|
//#### prüfe ob kundennummer vorhanden
|
|
if (kundennummer == null)
|
|
{
|
|
return Json("99", JsonRequestBehavior.AllowGet);
|
|
}
|
|
|
|
MobileSessionFacade.Tenant = kundennummer;
|
|
|
|
var isKundennummerVorhanden = ASPHibernateSessionManager.ConfigureHibernateSessionForWebService();
|
|
|
|
if (isKundennummerVorhanden)
|
|
{
|
|
var s = new UserServiceImp();
|
|
|
|
//ist benutzer und passwort richtig
|
|
if (s.IsUserValid(benutzername, passwort, null, "MobilClient", false) == UserValidationResult.UserValid)
|
|
{
|
|
var user = DAOFactory.UserDAO.FindUserByLoginName(benutzername); //Gibt nur ein employee zurück, was tun also wenn man den Klienten Link aufruft?
|
|
|
|
if (user == null || !DAOFactory.UserDAO.CheckPassword(user, passwort))
|
|
{
|
|
//gib json zurück {"STATE":1}
|
|
return Json("1", JsonRequestBehavior.AllowGet);
|
|
}
|
|
|
|
// MobileSessionFacade.LoggedInUser = user; // das wird garnicht gebraucht
|
|
|
|
|
|
Response.AddHeader("Content-Type","application/json"); //; charset=utf8
|
|
|
|
//Useroid übergeben auch nur dann wenn UserOid Vorhanden ist.
|
|
|
|
#region Typ Verarbeitung
|
|
|
|
if (typ != null)
|
|
{
|
|
if (typ.Equals("clients"))
|
|
{
|
|
//von employee ausgehend -> klienten die als betreuung gelistet aufrufen
|
|
|
|
//Klient Bereich
|
|
|
|
var alledaten = DAOFactory.GenericDAO.GetAllActive<Customer>();
|
|
|
|
|
|
List<JsonInputKlient2> inputList = new List<JsonInputKlient2>();
|
|
|
|
List<JsonInputKlient1> input1 = new List<JsonInputKlient1>();
|
|
|
|
var appUser = DAOFactory.GenericDAO.GetAllActive<ApplicationUser>();
|
|
|
|
// input 2 als liste übergeben und für jeden Mitarbeiter dem Customer zugeteilt ist
|
|
foreach (var daten in alledaten)
|
|
{
|
|
foreach (var e2c in daten.Employee2CustomerList)
|
|
{
|
|
foreach (var v2o in e2c.ValueList)
|
|
{
|
|
if (v2o.Entry.SystemEntryID.HasValue &&
|
|
v2o.Entry.SystemEntryID.Value == SystemEntryID.EmployeeRoleMainAttendant)
|
|
{
|
|
foreach (var applicationUser in appUser)
|
|
{
|
|
if (e2c.EmployeeOid == applicationUser.Employee.Oid)
|
|
{
|
|
JsonInputKlient2 input2 = new JsonInputKlient2("1", applicationUser.Oid.ToString(), e2c.EmployeeOid.ToString());
|
|
|
|
if (e2c.IsActive == ActivationTypeId.Deleted)
|
|
input2.Status = "3";
|
|
if (e2c.IsActive == ActivationTypeId.Archived)
|
|
input2.Status = "2";
|
|
|
|
|
|
inputList.Add(input2);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
|
|
JsonInputKlient1 input = new JsonInputKlient1(daten.Oid.ToString(),"1",
|
|
daten.Person.FirstName, daten.Person.LastName, daten.CustomerAlias, inputList);
|
|
|
|
|
|
if (daten.IsActive == ActivationTypeId.Deleted)
|
|
input.Status = "3";
|
|
if (daten.IsActive == ActivationTypeId.Archived)
|
|
input.Status = "2";
|
|
|
|
input1.Add(input);
|
|
|
|
}
|
|
|
|
var ssx = new JsonRueckgabeKlient("0", input1);
|
|
|
|
return Json(ssx, JsonRequestBehavior.AllowGet);
|
|
|
|
}
|
|
else if (typ.Equals("users"))
|
|
{
|
|
var empChatCode = DAOFactory.GenericDAO.GetAllActive<EmployeeAPPCode>();
|
|
|
|
var employee = DAOFactory.GenericDAO.GetAllActive<Employee>();
|
|
|
|
var applicationUser = DAOFactory.GenericDAO.GetAllActive<ApplicationUser>();
|
|
|
|
List< JsonRueckgabeMitarbeiterInput> miInputList = new List<JsonRueckgabeMitarbeiterInput>();
|
|
|
|
foreach (var daten in employee)
|
|
{
|
|
foreach (var appUser in applicationUser)
|
|
{
|
|
if (daten.Oid == appUser.Employee.Oid)
|
|
{
|
|
EmployeeAPPCode chatcode = new EmployeeAPPCode();
|
|
|
|
foreach (var code in empChatCode)
|
|
{
|
|
if (daten.Oid == code.EmployeeOid)
|
|
{
|
|
chatcode = code;
|
|
}
|
|
}
|
|
|
|
DateTime? insTs = null;
|
|
|
|
foreach (var img in daten.Person.Images)
|
|
{
|
|
insTs = img.InsTs.Value;
|
|
}
|
|
|
|
JsonRueckgabeMitarbeiterInput miInput;
|
|
|
|
if (daten.IsActive == ActivationTypeId.Deleted)
|
|
{
|
|
miInput = new JsonRueckgabeMitarbeiterInput("",
|
|
daten.Oid.ToString(), "3",
|
|
"", "", "", "", "", "", "", "");
|
|
|
|
}
|
|
else if (daten.IsActive == ActivationTypeId.Archived)
|
|
{
|
|
miInput = new JsonRueckgabeMitarbeiterInput("",
|
|
daten.Oid.ToString(), "2",
|
|
"", "", "", "", "", "", "", "");
|
|
}
|
|
else
|
|
{
|
|
String handy = null;
|
|
foreach (var contact in daten.Person.Contacts)
|
|
{
|
|
if (contact.Type == ContactType.business_MobilePhone)
|
|
{
|
|
//das ist die Handynummer
|
|
handy = contact.Value;
|
|
}
|
|
}
|
|
|
|
String instsStr = "";
|
|
if (insTs.HasValue)
|
|
{
|
|
instsStr = insTs.Value.ToString("dd.MM.yyyy");
|
|
|
|
}
|
|
|
|
miInput = new JsonRueckgabeMitarbeiterInput(appUser.Oid.ToString(),
|
|
daten.Oid.ToString(), "1", appUser.LoginName,
|
|
appUser.HashedPassword, daten.Person.FirstName,
|
|
daten.Person.LastName,
|
|
chatcode.EmployeeCode, handy, daten.Person.Oid.ToString(), instsStr);
|
|
|
|
if (insTs != null)
|
|
{
|
|
miInput.PictureId = insTs.ToString();
|
|
}
|
|
|
|
miInputList.Add(miInput);
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
JsonRueckgabeMitarbeiter mi = new JsonRueckgabeMitarbeiter("0", miInputList);
|
|
|
|
|
|
return Json(mi, JsonRequestBehavior.AllowGet);
|
|
|
|
}
|
|
else if (typ.Equals("teams"))
|
|
{
|
|
//Mitarbeiter Team Bereich
|
|
var daten = DAOFactory.GenericDAO.GetAllActive<Team>();
|
|
|
|
List<JsonRueckgabeTeamMitarbeiterInput> JRTMI = new List<JsonRueckgabeTeamMitarbeiterInput>();
|
|
|
|
|
|
foreach (var dat in daten)
|
|
{
|
|
foreach (var mem in dat.MemberList)
|
|
{
|
|
if (mem.Oid == user.Employee.Oid)
|
|
{
|
|
List<JsonRueckgabeTeamMitarbeiterInput2> mtInputList = new List<JsonRueckgabeTeamMitarbeiterInput2>();
|
|
|
|
foreach (var member in dat.MemberList)
|
|
{
|
|
JsonRueckgabeTeamMitarbeiterInput2 mtInput2 = new JsonRueckgabeTeamMitarbeiterInput2("1",
|
|
"UserOid", member.Oid.ToString());
|
|
|
|
if (member.IsActive == ActivationTypeId.Deleted)
|
|
mtInput2.Status = "3";
|
|
if (member.IsActive == ActivationTypeId.Archived)
|
|
mtInput2.Status = "2";
|
|
|
|
mtInputList.Add(mtInput2);
|
|
}
|
|
|
|
JsonRueckgabeTeamMitarbeiterInput mtInput1 = new JsonRueckgabeTeamMitarbeiterInput(dat.Oid.ToString(),"1", dat.Name, mtInputList);
|
|
|
|
if (dat.IsActive == ActivationTypeId.Deleted)
|
|
mtInput1.Status = "3";
|
|
if (dat.IsActive == ActivationTypeId.Archived)
|
|
mtInput1.Status = "2";
|
|
|
|
JRTMI.Add(mtInput1);
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
JsonRueckgabeTeamMitarbeiter mt = new JsonRueckgabeTeamMitarbeiter("0", JRTMI);
|
|
|
|
return Json(mt, JsonRequestBehavior.AllowGet);
|
|
}
|
|
//Falls typ nicht stimmt
|
|
return Json("1", JsonRequestBehavior.AllowGet);
|
|
}
|
|
|
|
#endregion
|
|
//fallsa typ nicht vorhanden
|
|
return Json("1", JsonRequestBehavior.AllowGet);
|
|
}
|
|
else
|
|
{
|
|
//gib json zurück {"STATE":1}
|
|
return Json("1", JsonRequestBehavior.AllowGet);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
//gib json zurück {"STATE":99}
|
|
return Json("99", JsonRequestBehavior.AllowGet);
|
|
}
|
|
|
|
return Json("99", JsonRequestBehavior.AllowGet);
|
|
}
|
|
|
|
public JsonResult BildUrl(int oid)
|
|
{
|
|
var img = DAOFactory.GenericDAO.GetByID<Person>(oid);
|
|
|
|
if(img.Images.Count > 0)
|
|
return Json(img.Images[0].SmallThumbnail, JsonRequestBehavior.AllowGet);
|
|
else
|
|
return Json("1", JsonRequestBehavior.AllowGet);
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
#region Klient
|
|
public class JsonRueckgabeKlient
|
|
{
|
|
public string State { get; set; }
|
|
|
|
public List<JsonInputKlient1> Input { get; set; }
|
|
|
|
public JsonRueckgabeKlient(string state, List<JsonInputKlient1> input )
|
|
{
|
|
State = state;
|
|
Input = input;
|
|
}
|
|
}
|
|
|
|
//klienten input
|
|
public class JsonInputKlient1
|
|
{
|
|
public string Oid { get; set; }
|
|
public string Status { get; set; }
|
|
public string Firstname { get; set; }
|
|
public string LastName { get; set; }
|
|
public string Alias { get; set; }
|
|
public List<JsonInputKlient2> Guardians { get; set; }
|
|
|
|
public JsonInputKlient1(string oid,string status, string firstname, string lastname, string alias, List<JsonInputKlient2> guardians)
|
|
{
|
|
Oid = oid;
|
|
Status = status;
|
|
Firstname = firstname;
|
|
LastName = lastname;
|
|
Alias = alias;
|
|
Guardians = guardians;
|
|
}
|
|
}
|
|
|
|
public class JsonInputKlient2
|
|
{
|
|
public string Status { get; set; }
|
|
|
|
public string UserOid { get; set; }
|
|
|
|
public string EmployeeOid { get; set; }
|
|
|
|
public JsonInputKlient2(string status, string userOid,string employeeOid)
|
|
{
|
|
Status = status;
|
|
UserOid = userOid;
|
|
EmployeeOid = employeeOid;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Mitarbeiter
|
|
|
|
public class JsonRueckgabeMitarbeiter
|
|
{
|
|
public string State { get; set; }
|
|
public List<JsonRueckgabeMitarbeiterInput> Input { get; set; }
|
|
|
|
public JsonRueckgabeMitarbeiter(string state, List<JsonRueckgabeMitarbeiterInput> input )
|
|
{
|
|
State = state;
|
|
Input = input;
|
|
}
|
|
}
|
|
|
|
public class JsonRueckgabeMitarbeiterInput
|
|
{
|
|
public string Useroid { get; set; }
|
|
public string EmployeeOid { get; set; }
|
|
public string Status { get; set; }
|
|
public string Login { get; set; }
|
|
public string Password { get; set; }
|
|
public string Firstname { get; set; }
|
|
public string LastName { get; set; }
|
|
public string ChatCode { get; set; }
|
|
public string Mobile { get; set; }
|
|
public string Picture { get; set; }
|
|
public string PictureId { get; set; }
|
|
|
|
|
|
public JsonRueckgabeMitarbeiterInput(string useroid, string employeeOid, string status, string login, string password,
|
|
string firstname, string lastname,string chatcode,string mobile,string picture,string pictureId)
|
|
{
|
|
Useroid = useroid;
|
|
EmployeeOid = employeeOid;
|
|
Status = status;
|
|
Login = login;
|
|
Password = password;
|
|
Firstname = firstname;
|
|
LastName = lastname;
|
|
ChatCode = chatcode;
|
|
Mobile = mobile;
|
|
Picture = picture;
|
|
PictureId = pictureId;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region TeamMitarbeiter
|
|
|
|
public class JsonRueckgabeTeamMitarbeiter
|
|
{
|
|
public string State { get; set; }
|
|
public List<JsonRueckgabeTeamMitarbeiterInput> Input { get; set; }
|
|
|
|
public JsonRueckgabeTeamMitarbeiter(string state, List<JsonRueckgabeTeamMitarbeiterInput> input)
|
|
{
|
|
State = state;
|
|
Input = input;
|
|
}
|
|
}
|
|
|
|
public class JsonRueckgabeTeamMitarbeiterInput
|
|
{
|
|
public string Oid { get; set; }
|
|
public string Status { get; set; }
|
|
public string Name { get; set; }
|
|
public List<JsonRueckgabeTeamMitarbeiterInput2> Member { get; set; }
|
|
|
|
public JsonRueckgabeTeamMitarbeiterInput(string oid,string status, string name,List<JsonRueckgabeTeamMitarbeiterInput2> member)
|
|
{
|
|
Oid = oid;
|
|
Name = name;
|
|
Member = member;
|
|
Status = status;
|
|
}
|
|
}
|
|
|
|
public class JsonRueckgabeTeamMitarbeiterInput2
|
|
{
|
|
public string Status { get; set; }
|
|
public string UserOid { get; set; }
|
|
public string EmployeeOid { get; set; }
|
|
|
|
public JsonRueckgabeTeamMitarbeiterInput2(string status, string userOid,string employeeOid)
|
|
{
|
|
Status = status;
|
|
UserOid = userOid;
|
|
EmployeeOid = employeeOid;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
}
|