407 lines
12 KiB
C#
407 lines
12 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 ChatTokenController : 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);
|
|
|
|
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"))
|
|
{
|
|
//Klient Bereich
|
|
|
|
var daten = DAOFactory.GenericDAO.LoadByID<Customer>(1);// was wird aus customer ?
|
|
|
|
|
|
List<JsonInputKlient2> inputList = new List<JsonInputKlient2>();
|
|
|
|
// input 2 als liste übergeben und für jeden Mitarbeiter dem Customer zugeteilt ist
|
|
|
|
foreach (var emp in daten.Employee2CustomerList)
|
|
{
|
|
if (emp.EmployeeOid == 1) //Unbedingt umbauen weil Hauptbetreuer Sollen geadded werden.
|
|
{
|
|
|
|
JsonInputKlient2 input2 = new JsonInputKlient2("1",user.Oid.ToString(), emp.EmployeeOid.ToString());
|
|
|
|
if (emp.IsActive == ActivationTypeId.Deleted)
|
|
input2.Status = "3";
|
|
if (emp.IsActive == ActivationTypeId.Archived)
|
|
input2.Status = "2";
|
|
|
|
|
|
inputList.Add(input2);
|
|
}
|
|
}
|
|
|
|
|
|
JsonInputKlient1 input1 = new JsonInputKlient1(daten.Oid.ToString(),"1",
|
|
daten.Person.FirstName, daten.Person.LastName, daten.CustomerAlias, inputList);
|
|
|
|
|
|
if (daten.IsActive == ActivationTypeId.Deleted)
|
|
input1.Status = "3";
|
|
if (daten.IsActive == ActivationTypeId.Archived)
|
|
input1.Status = "2";
|
|
|
|
var ssx = new JsonRueckgabeKlient("0", input1);
|
|
|
|
|
|
return Json(ssx, JsonRequestBehavior.AllowGet);
|
|
|
|
}
|
|
else if (typ.Equals("users"))
|
|
{
|
|
//Mitarbeiter Bereich
|
|
var daten = user;
|
|
|
|
var empChatCode = DAOFactory.GenericDAO.GetAllActive<EmployeeAPPCode>();
|
|
|
|
EmployeeAPPCode chatcode = new EmployeeAPPCode();
|
|
|
|
foreach (var code in empChatCode)
|
|
{
|
|
if (daten.Employee.Oid == code.EmployeeOid)
|
|
{
|
|
chatcode = code;
|
|
}
|
|
}
|
|
|
|
DateTime? insTs = null;
|
|
|
|
foreach (var img in daten.Employee.Person.Images)
|
|
{
|
|
insTs = img.InsTs.Value;
|
|
}
|
|
|
|
JsonRueckgabeMitarbeiterInput miInput;
|
|
|
|
|
|
//es kann sein das miInput in eine liste verändert werden muss um mehrere Users zu übergeben
|
|
//| kann alles nach belieben angepasst werden
|
|
if (daten.IsActive == ActivationTypeId.Deleted )
|
|
{
|
|
miInput = new JsonRueckgabeMitarbeiterInput("",
|
|
daten.Employee.Oid.ToString(),"3",
|
|
"","", "", "", "", "", "", "");
|
|
|
|
}else if (daten.IsActive == ActivationTypeId.Archived)
|
|
{
|
|
miInput = new JsonRueckgabeMitarbeiterInput("",
|
|
daten.Employee.Oid.ToString(),"2",
|
|
"", "", "", "", "", "", "", "");
|
|
}
|
|
else
|
|
{
|
|
miInput = new JsonRueckgabeMitarbeiterInput(user.Oid.ToString(),
|
|
daten.Employee.Oid.ToString(),"1", daten.LoginName,
|
|
daten.HashedPassword, daten.Employee.Person.FirstName, daten.Employee.Person.LastName,
|
|
chatcode.EmployeeCode, "Mobile number", daten.Employee.Person.Oid.ToString(), insTs.ToString()); // statt imageoid die person oid ubergeben
|
|
|
|
if (insTs != null)
|
|
{
|
|
miInput.PictureId = insTs.ToString();
|
|
}
|
|
}
|
|
|
|
JsonRueckgabeMitarbeiter mi = new JsonRueckgabeMitarbeiter("0", miInput);
|
|
|
|
|
|
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.Deleted)
|
|
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)
|
|
{
|
|
//Small thumbnail zurückschicken
|
|
//var img = DAOFactory.GenericDAO.GetAllActive<Image>(); // diese form von rausholden ist nicht möglich
|
|
var img = DAOFactory.GenericDAO.GetByID<Person>(oid);
|
|
|
|
//Erstmal doof image komplett zurück schicken nacher nur die image datei
|
|
return Json(img.Images[0].SmallThumbnail, JsonRequestBehavior.AllowGet);
|
|
}
|
|
|
|
|
|
}
|
|
|
|
#region Klient
|
|
public class JsonRueckgabeKlient
|
|
{
|
|
public string State { get; set; }
|
|
|
|
public JsonInputKlient1 Input { get; set; }
|
|
|
|
public JsonRueckgabeKlient(string state, 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 JsonRueckgabeMitarbeiterInput Input { get; set; }
|
|
|
|
public JsonRueckgabeMitarbeiter(string state, 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
|
|
|
|
|
|
}
|