190 lines
7.0 KiB
C#
190 lines
7.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using System.Linq;
|
|
using System.Web.Services;
|
|
|
|
using BeWo.Data.Access;
|
|
using BeWo.Service.ServiceContracts;
|
|
using BeWo.Service.ServiceImplementations;
|
|
|
|
using BeWoPlanerAndroid.Service;
|
|
|
|
using BS.Shared;
|
|
using BS.Shared.Core;
|
|
using BS.Shared.DataContracts.Compact;
|
|
using BS.Shared.Extensions;
|
|
using Newtonsoft.Json;
|
|
|
|
namespace BeWoPlanerAndroid
|
|
{
|
|
[WebService(Namespace = "bliblablubb.org/")]
|
|
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
|
|
[System.ComponentModel.ToolboxItem(false)]
|
|
// Wenn der Aufruf dieses Webdiensts aus einem Skript mithilfe von ASP.NET AJAX zulässig sein soll, heben Sie die Kommentarmarkierung für die folgende Zeile auf.
|
|
// [System.Web.Script.Services.ScriptService]
|
|
public class AndroidSoapService : WebService
|
|
{
|
|
protected readonly ICustomerService CustomerService = new MobileSessionFacade().CustomerService;
|
|
protected readonly IUserService UserService = new MobileSessionFacade().UserService;
|
|
protected readonly IEmployeeService EmployeeService = new MobileSessionFacade().EmployeeService;
|
|
|
|
public static string Tenant;
|
|
|
|
[WebMethod(EnableSession = true)]
|
|
public string Login(string pTenant, string pUsername, string pPassword)
|
|
{
|
|
MobileSessionFacade.Tenant = pTenant;
|
|
Tenant = pTenant;
|
|
|
|
SoapHibernateSessionManager.ConfigureHibernateSession();
|
|
|
|
var s = new UserServiceImp();
|
|
|
|
if(s.IsUserValid(pUsername, pPassword, null, "SOAPClient", false) == UserValidationResult.UserValid)
|
|
{
|
|
var user = DAOFactory.UserDAO.FindUserByLoginName(pUsername);
|
|
|
|
if (user == null || !DAOFactory.SearchDAO.CheckIfEmployeeIsAllowedToChat(user.Employee.Person.Oid.Value))
|
|
{
|
|
return null;
|
|
}
|
|
|
|
if(!DAOFactory.UserDAO.CheckPassword(user, pPassword))
|
|
{
|
|
return null;
|
|
}
|
|
|
|
MobileSessionFacade.LoggedInUser = user;
|
|
|
|
return user.Employee.Oid.Value + ";" + user.Employee.Person.FirstNameLastName + ";" + user.LoginName + ";" + user.Employee.Person.Oid.Value;
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
[WebMethod(EnableSession = true)]
|
|
public string TenantNochExistent()
|
|
{
|
|
SoapHibernateSessionManager.ConfigureHibernateSession();
|
|
|
|
var customer = CustomerService.GetCompactCustomerDC(46L);
|
|
|
|
var result = SerializeObject(customer);
|
|
|
|
return result;
|
|
}
|
|
|
|
[WebMethod(EnableSession = true)]
|
|
public void UpdateCustomer(string pParam)
|
|
{
|
|
var customerVonAndroidZurueck = JsonConvert.DeserializeObject<CompactCustomerDC>(pParam);
|
|
|
|
SoapHibernateSessionManager.ConfigureHibernateSession();
|
|
}
|
|
|
|
[WebMethod(EnableSession = true)]
|
|
public string GetAllChatMessagesForSenderAndRecipient(long pSenderPersonOid, long pRecipientPersonOid, string pExceptions, bool pIsForTeam)
|
|
{
|
|
Debug.WriteLine(pExceptions);
|
|
|
|
var exceptions = new List<long>();
|
|
|
|
if (pExceptions.Length > 0 && pExceptions.Contains(";"))
|
|
{
|
|
var splittedString = pExceptions.Split(';');
|
|
exceptions = splittedString.Select(item => Convert.ToInt64(item)).ToList();
|
|
}
|
|
|
|
var messages = DAOFactory.SearchDAO.FindAllChatMessagesForAndroid(pSenderPersonOid, pRecipientPersonOid, exceptions, pIsForTeam);
|
|
|
|
messages.DoForEach(dfe => Debug.WriteLine(dfe.Oid.Value));
|
|
|
|
return JsonConvert.SerializeObject(messages);
|
|
}
|
|
|
|
[WebMethod(EnableSession = true)]
|
|
public string GetServerAddressByToken(string pToken)
|
|
{
|
|
// Token überprüfen -> wenn falsch oder abgelaufen -> null zurückgeben
|
|
|
|
|
|
return pToken == null ? null : "das-nur-ein-test;demo";
|
|
}
|
|
|
|
[WebMethod(EnableSession = true)]
|
|
public string GetContactsForPerson(long pPersonOid)
|
|
{
|
|
// erst mal nur für Mitarbeiter
|
|
|
|
// employee oder customer laden
|
|
var employee = DAOFactory.SearchDAO.FindEmployeeWithPersonOid(pPersonOid);
|
|
var customer = DAOFactory.SearchDAO.FindCustomerWithPersonOid(pPersonOid);
|
|
|
|
var isEmployee = customer == null;
|
|
// mit den eigenen Klienten und allen anderen Mitarbeitern
|
|
|
|
var customerOids = employee.Employee2CustomerList.Select(s => s.CustomerOid.Value);
|
|
var customers = CustomerService.GetCompactCustomersById(customerOids);
|
|
|
|
var employees = EmployeeService.GetAllActiveEmployeesCompact().Where(w => !Equals(w.EmployeeOid, employee.Oid.Value));
|
|
|
|
var result = employees.Select(emp => new ChatPerson(emp.PersonOid, emp.FirstName + " " + emp.LastName, false, null, null)).ToList();
|
|
result.AddRange(customers.Select(cus => new ChatPerson(cus.PersonOid, cus.FullName, false, null, null)));
|
|
|
|
var teams = DAOFactory.SearchDAO.FindTeamsOfEmployee(employee.Oid.Value).Where(w => w.MemberList.Count > 1);
|
|
|
|
foreach(var team in teams)
|
|
{
|
|
var teamMembers = team.MemberList;
|
|
|
|
var memberString = "";
|
|
var memberNames = "";
|
|
foreach(var member in teamMembers)
|
|
{
|
|
memberString += member.Person.Oid.Value;
|
|
|
|
memberNames += member.Person.FirstNameLastName;
|
|
|
|
if(teamMembers.IndexOf(member) < teamMembers.Count - 1)
|
|
{
|
|
memberString += ";";
|
|
memberNames += ", ";
|
|
}
|
|
}
|
|
|
|
result.Add(new ChatPerson(team.Oid.Value, team.Name, true, memberString, memberNames));
|
|
}
|
|
|
|
return SerializeObject(result);
|
|
}
|
|
|
|
private static string SerializeObject(object obj)
|
|
{
|
|
return JsonConvert.SerializeObject(obj, Formatting.Indented, new JsonSerializerSettings { ContractResolver = new ShouldSerializeContractResolver(), ReferenceLoopHandling = ReferenceLoopHandling.Ignore });
|
|
}
|
|
|
|
public class ChatPerson
|
|
{
|
|
public long Oid { get; set; }
|
|
|
|
public string Name { get; set; }
|
|
|
|
public bool IsTeam { get; set; }
|
|
|
|
public string TeamMemberOids { get; set; }
|
|
|
|
public string TeamMemberNames { get; set; }
|
|
|
|
public ChatPerson(long pOid, string pName, bool pIsTeam, string pTeamMemberOids, string pTeamMemberNames)
|
|
{
|
|
Oid = pOid;
|
|
Name = pName;
|
|
IsTeam = pIsTeam;
|
|
TeamMemberOids = pTeamMemberOids;
|
|
TeamMemberNames = pTeamMemberNames;
|
|
}
|
|
}
|
|
}
|
|
}
|