564 lines
20 KiB
C#
564 lines
20 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Dynamic;
|
|
using System.Linq;
|
|
using System.Web;
|
|
using System.Web.Http;
|
|
using System.Web.Mvc;
|
|
using BeWo.Data.Access;
|
|
using BeWo.Data.Entities;
|
|
using BeWo.Service.ServiceImplementations;
|
|
using BeWoPlanerMobil.Service;
|
|
using BS.Shared;
|
|
using BS.Shared.Extensions;
|
|
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.";
|
|
}
|
|
|
|
|
|
[System.Web.Http.HttpPost]
|
|
public JsonResult LoginToken(string kundennummer, string typ)
|
|
{
|
|
var apikey = Request["API-KEY"];
|
|
|
|
|
|
//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();
|
|
|
|
|
|
OperationsServiceImp xc = new OperationsServiceImp();
|
|
|
|
var mandator = xc.GetMandator();
|
|
|
|
if (mandator.Apikey == apikey) {
|
|
|
|
// von hier bis hier
|
|
// 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}
|
|
// System.Threading.Thread.Sleep(5000);
|
|
// return Json("1", JsonRequestBehavior.AllowGet);
|
|
//}
|
|
|
|
//bis hier weg
|
|
|
|
// 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>();
|
|
|
|
var cusChatCode = DAOFactory.GenericDAO.GetAllActiveAndArchived<CustomerAPPCode>();
|
|
|
|
// List<JsonInputKlient2> inputList = new List<JsonInputKlient2>();
|
|
|
|
List<JsonInputKlient1> input1 = new List<JsonInputKlient1>();
|
|
|
|
var appUser = DAOFactory.GenericDAO.GetAllActiveAndArchived<ApplicationUser>();
|
|
|
|
// input 2 als liste übergeben und für jeden Mitarbeiter dem Customer zugeteilt ist
|
|
foreach (var daten in alledaten)
|
|
{
|
|
|
|
CustomerAPPCode chatcode = new CustomerAPPCode();
|
|
|
|
foreach (var code in cusChatCode)
|
|
{
|
|
if (daten.Oid == code.CustomerOid)
|
|
{
|
|
chatcode = code;
|
|
}
|
|
}
|
|
|
|
|
|
List<JsonInputKlient2> inputList = new List<JsonInputKlient2>();
|
|
|
|
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", e2c.EmployeeOid.ToString());
|
|
|
|
if (e2c.IsActive == ActivationTypeId.Deleted)
|
|
input2.Status = "3";
|
|
if (e2c.IsActive == ActivationTypeId.Archived)
|
|
input2.Status = "2";
|
|
|
|
inputList.Add(input2);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
string mobilnummer = "";
|
|
foreach (var contact in daten.Person.Contacts)
|
|
{
|
|
if (contact.Type == ContactType.business_MobilePhone)
|
|
{
|
|
//das ist die Handynummer
|
|
mobilnummer = contact.Value;
|
|
}
|
|
}
|
|
|
|
JsonInputKlient1 input = new JsonInputKlient1(daten.Oid.ToString(),"1",
|
|
daten.Person.FirstName, daten.Person.LastName, daten.CustomerAlias, mobilnummer, chatcode.CustomerCode,chatcode.BenutzerName,chatcode.BCryptPassword, 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"))
|
|
{
|
|
|
|
//Bitte alle Employees zurückgeben
|
|
var empChatCode = DAOFactory.GenericDAO.GetAllActiveAndArchived<EmployeeAPPCode>();
|
|
|
|
var employee = DAOFactory.GenericDAO.GetAllActiveAndArchived<Employee>();
|
|
|
|
var applicationUser = DAOFactory.GenericDAO.GetAllActiveAndArchived<ApplicationUser>();
|
|
|
|
List< JsonRueckgabeMitarbeiterInput> miInputList = new List<JsonRueckgabeMitarbeiterInput>();
|
|
|
|
Dictionary<long? , ApplicationUser> appus = new Dictionary<long?, ApplicationUser>();
|
|
|
|
foreach (var appUser in applicationUser)
|
|
{
|
|
appus.Add(appUser.Employee.Oid,appUser);
|
|
}
|
|
|
|
foreach (var daten in employee)
|
|
{
|
|
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");
|
|
|
|
}
|
|
|
|
|
|
if (appus.ContainsKey(daten.Oid))
|
|
{
|
|
miInput = new JsonRueckgabeMitarbeiterInput(appus[daten.Oid].Oid.ToString(),
|
|
daten.Oid.ToString(), "1", appus[daten.Oid].LoginName,
|
|
appus[daten.Oid].BCryptPassword, daten.Person.FirstName,
|
|
daten.Person.LastName,
|
|
chatcode.EmployeeCode, handy, daten.Person.Oid.ToString(), instsStr);
|
|
}
|
|
else
|
|
{
|
|
miInput = new JsonRueckgabeMitarbeiterInput("",
|
|
daten.Oid.ToString(), "1", "",
|
|
"", 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>();
|
|
|
|
var applicationUser = DAOFactory.GenericDAO.GetAllActiveAndArchived<ApplicationUser>();
|
|
Dictionary<long?, ApplicationUser> appus = new Dictionary<long?, ApplicationUser>();
|
|
|
|
foreach (var appUser in applicationUser)
|
|
{
|
|
appus.Add(appUser.Employee.Oid, appUser);
|
|
}
|
|
|
|
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)
|
|
{
|
|
if (appus.ContainsKey(member.Oid))
|
|
{
|
|
JsonRueckgabeTeamMitarbeiterInput2 mtInput2 = new JsonRueckgabeTeamMitarbeiterInput2("1",member.Oid.ToString());
|
|
|
|
|
|
if (member.IsActive == ActivationTypeId.Deleted)
|
|
mtInput2.Status = "3";
|
|
if (member.IsActive == ActivationTypeId.Archived)
|
|
mtInput2.Status = "2";
|
|
|
|
mtInputList.Add(mtInput2);
|
|
}
|
|
else
|
|
{
|
|
JsonRueckgabeTeamMitarbeiterInput2 mtInput2 = new JsonRueckgabeTeamMitarbeiterInput2("1",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
|
|
|
|
System.Threading.Thread.Sleep(5000);
|
|
return Json(new Fehler("1"), JsonRequestBehavior.AllowGet);
|
|
}
|
|
|
|
#endregion
|
|
//fallsa typ nicht vorhanden
|
|
System.Threading.Thread.Sleep(5000);
|
|
return Json(new Fehler("1"), JsonRequestBehavior.AllowGet);
|
|
}
|
|
else
|
|
{
|
|
//gib json zurück {"STATE":1}
|
|
System.Threading.Thread.Sleep(5000);
|
|
return Json(new Fehler("1"), JsonRequestBehavior.AllowGet);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
//gib json zurück {"STATE":99}
|
|
return Json(new Fehler("99"), JsonRequestBehavior.AllowGet);
|
|
}
|
|
|
|
return Json(new Fehler("99"), JsonRequestBehavior.AllowGet);
|
|
}
|
|
|
|
[System.Web.Mvc.HttpPost]
|
|
public JsonResult BildUrl()
|
|
{
|
|
var oid = Request["oid"];
|
|
var img = DAOFactory.GenericDAO.GetByID<Person>(Convert.ToInt64(oid));
|
|
|
|
if (img.Images.Count > 0)
|
|
return Json(img.Images[0].SmallThumbnail, JsonRequestBehavior.AllowGet);
|
|
else
|
|
{
|
|
System.Threading.Thread.Sleep(5000);
|
|
return Json(new Fehler("1"), JsonRequestBehavior.AllowGet);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
#region Klient
|
|
public class JsonRueckgabeKlient
|
|
{
|
|
public string State { get; set; }
|
|
|
|
public List<JsonInputKlient1> Data { get; set; }
|
|
|
|
public JsonRueckgabeKlient(string state, List<JsonInputKlient1> data )
|
|
{
|
|
State = state;
|
|
Data = data;
|
|
}
|
|
}
|
|
|
|
//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 string Mobile { get; set; }
|
|
public string ChatCode { get; set; }
|
|
public string Login { get; set; }
|
|
public string Password { get; set; }
|
|
|
|
public List<JsonInputKlient2> Guardians { get; set; }
|
|
|
|
public JsonInputKlient1(string oid,string status, string firstname, string lastname, string alias,string mobile,string chatCode,string login,string password, List<JsonInputKlient2> guardians)
|
|
{
|
|
Oid = "C"+oid;
|
|
Status = status;
|
|
Firstname = firstname;
|
|
LastName = lastname;
|
|
Alias = alias;
|
|
Mobile = mobile;
|
|
ChatCode = chatCode;
|
|
Login = login;
|
|
Password = password;
|
|
Guardians = guardians;
|
|
}
|
|
}
|
|
|
|
public class JsonInputKlient2
|
|
{
|
|
public string Status { get; set; }
|
|
|
|
public string EmployeeOid { get; set; }
|
|
|
|
public JsonInputKlient2(string status,string employeeOid)
|
|
{
|
|
Status = status;
|
|
EmployeeOid = "E"+employeeOid;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Mitarbeiter
|
|
|
|
public class JsonRueckgabeMitarbeiter
|
|
{
|
|
public string State { get; set; }
|
|
public List<JsonRueckgabeMitarbeiterInput> Data { get; set; }
|
|
|
|
public JsonRueckgabeMitarbeiter(string state, List<JsonRueckgabeMitarbeiterInput> data)
|
|
{
|
|
State = state;
|
|
Data = data;
|
|
}
|
|
}
|
|
|
|
public class JsonRueckgabeMitarbeiterInput
|
|
{
|
|
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)
|
|
{
|
|
EmployeeOid = "E"+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> Data { get; set; }
|
|
|
|
public JsonRueckgabeTeamMitarbeiter(string state, List<JsonRueckgabeTeamMitarbeiterInput> data)
|
|
{
|
|
State = state;
|
|
Data = data;
|
|
}
|
|
}
|
|
|
|
public class JsonRueckgabeTeamMitarbeiterInput
|
|
{
|
|
public string Oid { get; set; }
|
|
public string Status { get; set; }
|
|
public string Name { get; set; }
|
|
public List<JsonRueckgabeTeamMitarbeiterInput2> Members { get; set; }
|
|
|
|
public JsonRueckgabeTeamMitarbeiterInput(string oid,string status, string name,List<JsonRueckgabeTeamMitarbeiterInput2> members)
|
|
{
|
|
Oid = "T"+oid;
|
|
Name = name;
|
|
Members = members;
|
|
Status = status;
|
|
}
|
|
}
|
|
|
|
public class JsonRueckgabeTeamMitarbeiterInput2
|
|
{
|
|
public string Status { get; set; }
|
|
|
|
public string EmployeeOid { get; set; }
|
|
|
|
public JsonRueckgabeTeamMitarbeiterInput2(string status,string employeeOid)
|
|
{
|
|
Status = status;
|
|
|
|
EmployeeOid = "E"+employeeOid;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region fehlermeldung
|
|
public class Fehler
|
|
{
|
|
public string STATE { get; set; }
|
|
|
|
public Fehler(string fehler)
|
|
{
|
|
STATE = fehler;
|
|
}
|
|
}
|
|
#endregion
|
|
}
|