2016-08-17 12:20:27 +02:00
using System ;
using System.Collections.Generic ;
using System.Diagnostics ;
using System.Linq ;
2016-06-27 01:45:38 +02:00
using System.Web.Services ;
using BeWo.Data.Access ;
using BeWo.Service.ServiceContracts ;
using BeWo.Service.ServiceImplementations ;
using BeWoPlanerAndroid.Service ;
2016-07-18 06:14:17 +02:00
2016-06-27 01:45:38 +02:00
using BS.Shared ;
using BS.Shared.Core ;
using BS.Shared.DataContracts.Compact ;
2016-08-17 12:20:27 +02:00
using BS.Shared.Extensions ;
2016-06-27 01:45:38 +02:00
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 ) ;
2016-08-17 12:20:27 +02:00
if ( user = = null | | ! DAOFactory . SearchDAO . CheckIfEmployeeIsAllowedToChat ( user . Employee . Person . Oid . Value ) )
{
return null ;
}
if ( ! DAOFactory . UserDAO . CheckPassword ( user , pPassword ) )
2016-06-27 01:45:38 +02:00
{
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 ( ) ;
}
2016-07-29 13:08:32 +02:00
[WebMethod(EnableSession = true)]
2016-08-17 12:20:27 +02:00
public string GetAllChatMessagesForSenderAndRecipient ( long pSenderPersonOid , long pRecipientPersonOid , string pExceptions , bool pIsForTeam )
2016-07-29 13:08:32 +02:00
{
2016-08-17 12:20:27 +02:00
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 ) ;
2016-07-29 13:08:32 +02:00
2016-08-17 16:37:40 +02:00
messages . DoForEach ( dfe = > Debug . WriteLine ( dfe . Oid . Value ) ) ;
2016-07-29 13:08:32 +02:00
return JsonConvert . SerializeObject ( messages ) ;
}
2016-06-27 01:45:38 +02:00
[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 ) ) ;
2016-08-26 12:28:57 +02:00
var result = employees . Select ( emp = > new ChatPerson ( emp . PersonOid , emp . FirstName + " " + emp . LastName , false , null , null , emp . Version ) ) . ToList ( ) ;
result . AddRange ( customers . Select ( cus = > new ChatPerson ( cus . PersonOid , cus . FullName , false , null , null , cus . Version ) ) ) ;
2016-08-17 12:20:27 +02:00
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 + = ", " ;
}
}
2016-08-26 12:28:57 +02:00
result . Add ( new ChatPerson ( team . Oid . Value , team . Name , true , memberString , memberNames , team . Version . Value ) ) ;
2016-08-17 12:20:27 +02:00
}
2016-06-27 01:45:38 +02:00
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 ; }
2016-08-17 12:20:27 +02:00
public bool IsTeam { get ; set ; }
public string TeamMemberOids { get ; set ; }
public string TeamMemberNames { get ; set ; }
2016-08-26 12:28:57 +02:00
public long Version { get ; set ; }
public ChatPerson ( long pOid , string pName , bool pIsTeam , string pTeamMemberOids , string pTeamMemberNames , long pVersion )
2016-06-27 01:45:38 +02:00
{
2016-08-26 12:28:57 +02:00
Oid = pOid ;
Name = pName ;
IsTeam = pIsTeam ;
TeamMemberOids = pTeamMemberOids ;
2016-08-17 12:20:27 +02:00
TeamMemberNames = pTeamMemberNames ;
2016-08-26 12:28:57 +02:00
Version = pVersion ;
2016-06-27 01:45:38 +02:00
}
}
}
}