protected CFunctionResult _getMenuActive(string UserIdentity, string Passhash, Guid SessionID, decimal OrganizationKey) { Dictionary<string, object> InputParameters = new Dictionary<string, object>(); InputParameters.Add("UserIdentity", UserIdentity); InputParameters.Add("Passhash", Passhash); InputParameters.Add("SessionID", SessionID.ToString().ToUpper()); InputParameters.Add("OrganizationKey", OrganizationKey); CFunctionResult R = new CFunctionResult() { FunctionID = "GetMenuActive", InputParameters = InputParameters, ResultType = Communication.EnFunctionResultType.ESuccess }; if (OrganizationKey == null) { R = CServerHelper.sCompileFunctionResult("GetMenuActive", Communication.EnFunctionResultType.EError, InputParameters, CGlobalizationHelper.sGetStringResource("ERROR_OBJECT_KEY_NULL", CultureInfo.CurrentCulture), null); return R; } CFunctionResult UserResult = CServerHelper.sCheckUser(UserIdentity, Passhash, SessionID); if (UserResult.ResultType != Communication.EnFunctionResultType.ESuccess) { UserResult.FunctionID = "GetMenuActive"; UserResult.InputParameters = InputParameters; return UserResult; } COrganization Organization = new COrganization(OrganizationKey, CServerEnvironment.DataContext); if (Organization.ID == Guid.Empty) { R = CServerHelper.sCompileFunctionResult("GetMenuActive", Communication.EnFunctionResultType.EError, InputParameters, CGlobalizationHelper.sGetStringResource("ERROR_OBJECT_UNABLE_TO_FIND", CultureInfo.CurrentCulture), null); return R; } var Menus = Organization.GetChildren(CServerEnvironment.DataContext, false); CMenu ActiveMenu = null; foreach (CMenu Menu in Menus) { if (Menu.Primary) { ActiveMenu = Menu; break; } } if (ActiveMenu == null) { R = CServerHelper.sCompileFunctionResult("GetMenuActive", Communication.EnFunctionResultType.EError, InputParameters, CGlobalizationHelper.sGetStringResource("ERROR_ACTIVE_MENU_NULL", CultureInfo.CurrentCulture), null); return R; } ActiveMenu.GetChildren(CServerEnvironment.DataContext, false); R.Content = ActiveMenu; return R; }
protected CFunctionResult _getOrderInformation(string UserIdentity, string Passhash, Guid SessionID, decimal OrderKey) { Dictionary<string, object> InputParameters = new Dictionary<string, object>(); InputParameters.Add("UserIdentity", UserIdentity); InputParameters.Add("Passhash", Passhash); InputParameters.Add("SessionID", SessionID.ToString().ToUpper()); InputParameters.Add("OrderKey", OrderKey); CFunctionResult R = new CFunctionResult() { FunctionID = "GetOrderInformation", InputParameters = InputParameters, ResultType = Communication.EnFunctionResultType.ESuccess }; if (OrderKey == null) { R = CServerHelper.sCompileFunctionResult("GetOrderInformation", Communication.EnFunctionResultType.EError, InputParameters, CGlobalizationHelper.sGetStringResource("ERROR_OBJECT_KEY_NULL", CultureInfo.CurrentCulture), null); return R; } CFunctionResult UserResult = CServerHelper.sCheckUser(UserIdentity, Passhash, SessionID); if (UserResult.ResultType != Communication.EnFunctionResultType.ESuccess) { UserResult.FunctionID = "GetOrderInformation"; UserResult.InputParameters = InputParameters; return UserResult; } CSystemUser User = (CSystemUser)(UserResult.Content as object[])[0]; CSystemUserSession Session = (CSystemUserSession)(UserResult.Content as object[])[1]; CMenuServiceOrder Order = new CMenuServiceOrder(); Order.Key = OrderKey; Order.OrderGetByKey(CServerEnvironment.DataContext); if (Order.ID == Guid.Empty) { R = CServerHelper.sCompileFunctionResult("GetOrderInformation", Communication.EnFunctionResultType.EError, InputParameters, CGlobalizationHelper.sGetStringResource("ERROR_OBJECT_UNABLE_TO_FIND", CultureInfo.CurrentCulture), null); return R; } if (Session.Key != Order.SessionKey) { R = CServerHelper.sCompileFunctionResult("GetOrderInformation", Communication.EnFunctionResultType.EError, InputParameters, CGlobalizationHelper.sGetStringResource("ERROR_SESSION_KEYS_NOT_EQUALS", CultureInfo.CurrentCulture), null); return R; } Order.GetAmounts(CServerEnvironment.DataContext); R.Content = Order; return R; }
public static CFunctionResult sCompileFunctionResult(string FunctionID, EnFunctionResultType Type, Dictionary<string, object> Parameters, string Message, object Content) { CFunctionResult R = new CFunctionResult { ResultType = Type, InputParameters = Parameters, Message = Message, Content = Content, FunctionID = FunctionID }; return R; }
protected CFunctionResult _organizationGetInformation(string UserIdentity, string Passhash, Guid SessionID, Guid ID) { Dictionary<string, object> InputParameters = new Dictionary<string, object>(); InputParameters.Add("UserIdentity", UserIdentity); InputParameters.Add("Passhash", Passhash); InputParameters.Add("SessionID", SessionID.ToString().ToUpper()); InputParameters.Add("ID", ID); CFunctionResult R = new CFunctionResult() { FunctionID = "OrganizationGetInformation", InputParameters = InputParameters, ResultType = Communication.EnFunctionResultType.ESuccess }; if (ID == null) { R = CServerHelper.sCompileFunctionResult("OrganizationGetInformation", Communication.EnFunctionResultType.EError, InputParameters, CGlobalizationHelper.sGetStringResource("ERROR_OBJECT_ID_NULL", CultureInfo.CurrentCulture), null); return R; } CFunctionResult UserResult = CServerHelper.sCheckUser(UserIdentity, Passhash, SessionID); if (UserResult.ResultType != Communication.EnFunctionResultType.ESuccess) { UserResult.FunctionID = "OrganizationGetInformation"; UserResult.InputParameters = InputParameters; return UserResult; } COrganization Organization = new COrganization(ID, CServerEnvironment.DataContext); if (Organization.Key == CDBConst.CONST_OBJECT_EMPTY_KEY) { R = CServerHelper.sCompileFunctionResult("OrganizationGetInformation", Communication.EnFunctionResultType.EError, InputParameters, CGlobalizationHelper.sGetStringResource("ERROR_OBJECT_UNABLE_TO_FIND", CultureInfo.CurrentCulture), null); return R; } R.Content = Organization; return R; }
protected CFunctionResult _getCategoryInformation(string UserIdentity, string Passhash, Guid SessionID, decimal CategoryKey) { Dictionary<string, object> InputParameters = new Dictionary<string, object>(); InputParameters.Add("UserIdentity", UserIdentity); InputParameters.Add("Passhash", Passhash); InputParameters.Add("SessionID", SessionID.ToString().ToUpper()); InputParameters.Add("CategoryKey", CategoryKey); CFunctionResult R = new CFunctionResult() { FunctionID = "GetCategoryInformation", InputParameters = InputParameters, ResultType = Communication.EnFunctionResultType.ESuccess }; if (CategoryKey == null) { R = CServerHelper.sCompileFunctionResult("GetCategoryInformation", Communication.EnFunctionResultType.EError, InputParameters, CGlobalizationHelper.sGetStringResource("ERROR_OBJECT_KEY_NULL", CultureInfo.CurrentCulture), null); return R; } CFunctionResult UserResult = CServerHelper.sCheckUser(UserIdentity, Passhash, SessionID); if (UserResult.ResultType != Communication.EnFunctionResultType.ESuccess) { UserResult.FunctionID = "GetCategoryInformation"; UserResult.InputParameters = InputParameters; return UserResult; } CCategory Category = new CCategory(CategoryKey, CServerEnvironment.DataContext); if (Category.ID == Guid.Empty) { R = CServerHelper.sCompileFunctionResult("GetCategoryInformation", Communication.EnFunctionResultType.EError, InputParameters, CGlobalizationHelper.sGetStringResource("ERROR_OBJECT_UNABLE_TO_FIND", CultureInfo.CurrentCulture), null); return R; } Category.GetChildren(CServerEnvironment.DataContext, false); R.Content = Category; return R; }
public virtual CFunctionResult Execute(Dictionary<string, object> Parameters) { CFunctionResult Result = new CFunctionResult(); Result.FunctionID = "VIRTUAL"; return Result; }
protected CFunctionResult _userCheckPhoneExistence(string Phone) { var InputParameters = new Dictionary<string, object>(); InputParameters.Add("Phone", Phone); var R = new CFunctionResult() { FunctionID = "UserCheckPhoneExistence", InputParameters = InputParameters, ResultType = Communication.EnFunctionResultType.ESuccess }; var User = CSystemUser.sGetUserByMobilePhone(Phone, CServerEnvironment.DataContext); if (User != null) R = CServerHelper.sCompileFunctionResult("UserCheckPhoneExistence", Communication.EnFunctionResultType.ESuccess, InputParameters, "", User); return R; }
protected CFunctionResult _userCheckLoginExistence(string Login) { var InputParameters = new Dictionary<string, object>(); InputParameters.Add("Login", Login); var R = new CFunctionResult() { FunctionID = "UserCheckLoginExistence", InputParameters = InputParameters, ResultType = Communication.EnFunctionResultType.ESuccess, Message = CGlobalizationHelper.sGetStringResource("ERROR_OBJECT_UNABLE_TO_FIND", CultureInfo.CurrentCulture) }; var User = CSystemUser.sGetUserByLogin(Login, CServerEnvironment.DataContext); if (User != null) R = CServerHelper.sCompileFunctionResult("UserCheckLoginExistence", Communication.EnFunctionResultType.ESuccess, InputParameters, "", User); return R; }
protected CFunctionResult _userGetInformation(string UserIdentity, string Passhash, Guid SessionID, Guid ID) { Dictionary<string, object> InputParameters = new Dictionary<string, object>(); InputParameters.Add("ID", ID); CFunctionResult R = new CFunctionResult() { FunctionID = "UserGetInformation", InputParameters = InputParameters, ResultType = Communication.EnFunctionResultType.ESuccess }; CFunctionResult UserResult = CServerHelper.sCheckUser(UserIdentity, Passhash, SessionID); if (UserResult.ResultType != Communication.EnFunctionResultType.ESuccess) { UserResult.FunctionID = "UserLogout"; UserResult.InputParameters = InputParameters; return UserResult; } CSystemUser User = new CSystemUser(ID, CServerEnvironment.DataContext); if (User.Key == CDBConst.CONST_OBJECT_EMPTY_KEY|| User.Class != EnMetaobjectClass.ESystemUser) R = CServerHelper.sCompileFunctionResult("UserGetInformation", Communication.EnFunctionResultType.EError, InputParameters, CGlobalizationHelper.sGetStringResource("ERROR_OBJECT_UNABLE_TO_FIND", CultureInfo.CurrentCulture), null); else R = CServerHelper.sCompileFunctionResult("UserGetInformation", Communication.EnFunctionResultType.ESuccess, InputParameters, "", User); return R; }
protected CFunctionResult _userLogin(string UserIdentity, string Password, Guid TableID) { Dictionary<string, object> InputParameters = new Dictionary<string, object>(); InputParameters.Add("IdentityKey", UserIdentity); InputParameters.Add("Password", Password); InputParameters.Add("TableID", TableID); CFunctionResult R = new CFunctionResult() { FunctionID = "UserLogin", InputParameters = InputParameters, ResultType = Communication.EnFunctionResultType.ESuccess }; CFunctionResult UserResult = CServerHelper.sCheckUserByPassword(UserIdentity, Password); if (UserResult.ResultType != Communication.EnFunctionResultType.ESuccess) { UserResult.FunctionID = "UserLogout"; UserResult.InputParameters = InputParameters; return UserResult; } CSystemUser User = (CSystemUser)UserResult.Content; Guid TempGUID = TableID; COrganizationTable Table = new COrganizationTable(TempGUID, CServerEnvironment.DataContext); if (Table.Key == CDBConst.CONST_OBJECT_EMPTY_KEY) { R = CServerHelper.sCompileFunctionResult("UserLogin", Communication.EnFunctionResultType.EError, InputParameters, CGlobalizationHelper.sGetStringResource("ERROR_TABLE_UNABLE_TO_FIND", CultureInfo.CurrentCulture), null); return R; } var Links = Table.GetExternalLinks(CServerEnvironment.DataContext); if (Links.Count == 0 || Links.Count > 1) { R = CServerHelper.sCompileFunctionResult("UserLogin", Communication.EnFunctionResultType.EError, InputParameters, CGlobalizationHelper.sGetStringResource("ERROR_ORG_UNABLE_TO_FIND", CultureInfo.CurrentCulture), null); return R; } cMenu.Metaobjects.Linq.CMetaobject Organization = Links[0].GetSourceObject(CServerEnvironment.DataContext); if (Organization == null) { R = CServerHelper.sCompileFunctionResult("UserLogin", Communication.EnFunctionResultType.EError, InputParameters, CGlobalizationHelper.sGetStringResource("ERROR_ORG_UNABLE_TO_FIND", CultureInfo.CurrentCulture), null); return R; } var Sessions = CSystemUserSession.sGetSessionsByUser(User.Key, CServerEnvironment.DataContext); CSystemUserSession Session = null; if (Sessions.Count != 0) { var Query = from Ses in Sessions where Ses.Status == EnSessionStatus.EEnabled && Ses.Type == EnSessionType.ETablet && Ses.DeadLine > DateTime.Now select Ses; Session = (Query.Count() == 0 ? null : Query.ToList()[0]); if (Session == null) { Session = new CSystemUserSession() { ID = Guid.NewGuid(), Key = CDatabaseSequence.sGetObjectKey(CServerEnvironment.DatabaseProvider), Status = EnSessionStatus.EEnabled, Type = EnSessionType.ETablet, UserKey = User.Key, Variables = new byte[0], DeadLine = DateTime.Now.AddHours(8) }; Session.VariablesDictionary.Add(CSecurityConsts.CONST_SESSION_TABLE_ID, Table.ID); Session.SessionVariablesSave(); var RR = Session.SessionInsert(CServerEnvironment.DataContext); if (RR != CErrors.ERR_SUC) { R = CServerHelper.sCompileFunctionResult("UserLogin", Communication.EnFunctionResultType.EError, InputParameters, CGlobalizationHelper.sGetStringResource("ERROR_SESSION_INSERT_UNABLE", CultureInfo.CurrentCulture), null); return R; } } else Session.SessionVariablesLoad(); } else { Session = new CSystemUserSession() { ID = Guid.NewGuid(), Key = CDatabaseSequence.sGetObjectKey(CServerEnvironment.DatabaseProvider), Status = EnSessionStatus.EEnabled, Type = EnSessionType.ETablet, UserKey = User.Key, Variables = new byte[0], DeadLine = DateTime.Now.AddHours(8) }; Session.VariablesDictionary.Add(CSecurityConsts.CONST_SESSION_TABLE_ID, Table.ID); Session.SessionVariablesSave(); var RR = Session.SessionInsert(CServerEnvironment.DataContext); if (RR != CErrors.ERR_SUC) { R = CServerHelper.sCompileFunctionResult("UserLogin", Communication.EnFunctionResultType.EError, InputParameters, CGlobalizationHelper.sGetStringResource("ERROR_SESSION_INSERT_UNABLE", CultureInfo.CurrentCulture), null); return R; } } try { CServerEnvironment.DataContext.SubmitChanges(); } catch (Exception Exception) { R = CServerHelper.sCompileFunctionResult("UserLogin", Communication.EnFunctionResultType.EError, InputParameters, Exception.Message, null); return R; } var Content = new object[3]; Content[0] = User; Content[1] = Session; Content[2] = Organization; R.Content = Content; return R; }
public static CFunctionResult sCheckUserByPassword(string UserIdentity, string Password) { CFunctionResult R = new CFunctionResult() { FunctionID = "CheckUser", ResultType = EnFunctionResultType.ESuccess }; if (UserIdentity == null || Password == null) { R = CServerHelper.sCompileFunctionResult("CheckUser", Communication.EnFunctionResultType.EError, null, "ERROR_USER_INPUT_PARAMS_NULL", null); return R; } if (UserIdentity.Trim() == "") { R = CServerHelper.sCompileFunctionResult("CheckUser", Communication.EnFunctionResultType.EError, null, "ERROR_USER_INPUT_PARAMS_NULL", null); return R; } CSystemUser User = null; User = CSystemUser.sGetUserByLogin(UserIdentity.Trim(), CServerEnvironment.DataContext); if (User == null) { User = CSystemUser.sGetUserByEmail(UserIdentity.Trim(), CServerEnvironment.DataContext); if (User == null) User = CSystemUser.sGetUserByMobilePhone(UserIdentity.Trim(), CServerEnvironment.DataContext); } if (User == null) { R = CServerHelper.sCompileFunctionResult("CheckUser", Communication.EnFunctionResultType.EError, null, "ERROR_OBJECT_UNABLE_TO_FIND", null); return R; } var Verified = CSecurityHelper.sVerifyPasshash(User.Login, Password, User.Passhash); if (!Verified) { R = CServerHelper.sCompileFunctionResult("CheckUser", Communication.EnFunctionResultType.EError, null, "ERROR_USER_BAD_IDENTITY_OR_PASS", null); return R; } R.Content = User; return R; }
protected CFunctionResult _userLogout(string UserIdentity, string Passhash, Guid SessionID) { Dictionary<string, object> InputParameters = new Dictionary<string, object>(); InputParameters.Add("UserIdentity", UserIdentity); InputParameters.Add("Passhash", Passhash); CFunctionResult R = new CFunctionResult() { FunctionID = "UserLogout", InputParameters = InputParameters, ResultType = Communication.EnFunctionResultType.ESuccess }; CFunctionResult UserResult = CServerHelper.sCheckUser(UserIdentity, Passhash, SessionID); if (UserResult.ResultType != Communication.EnFunctionResultType.ESuccess) { UserResult.FunctionID = "UserLogout"; UserResult.InputParameters = InputParameters; return UserResult; } CSystemUser User = (CSystemUser)UserResult.Content; var Sessions = CSystemUserSession.sGetSessionsByUser(User.Key, CServerEnvironment.DataContext); foreach (CSystemUserSession Session in Sessions) { if (Session.Type == EnSessionType.ETablet) Session.Status = EnSessionStatus.EClosed; var RR = Session.SessionUpdate(CServerEnvironment.DataContext); if (RR != CErrors.ERR_SUC) { R = CServerHelper.sCompileFunctionResult("UserLogout", Communication.EnFunctionResultType.EError, InputParameters, CGlobalizationHelper.sGetStringResource("ERROR_SESSION_UPDATE_UNABLE", CultureInfo.CurrentCulture), null); return R; } } try { CServerEnvironment.DataContext.SubmitChanges(); } catch (Exception) { R = CServerHelper.sCompileFunctionResult("UserLogout", Communication.EnFunctionResultType.EError, InputParameters, CGlobalizationHelper.sGetStringResource("ERROR_SESSION_UPDATE_UNABLE", CultureInfo.CurrentCulture), null); return R; } return R; }
protected CFunctionResult _userRegister(string Login, string Email, string Phone, string Password) { var InputParameters = new Dictionary<string, object>(); InputParameters.Add("Login", Login); InputParameters.Add("Email", Email); InputParameters.Add("Phone", Phone); InputParameters.Add("Password", Password); CFunctionResult R = new CFunctionResult() { FunctionID = "UserRegister", InputParameters = InputParameters, ResultType = Communication.EnFunctionResultType.ESuccess }; CFunctionResult TempResult = null; if (Login.Trim() == "" && Email.Trim() == "" && Phone.Trim() == "") { R = CServerHelper.sCompileFunctionResult("UserRegister", Communication.EnFunctionResultType.EError, InputParameters, CGlobalizationHelper.sGetStringResource("ERROR_USER_INPUT_PARAMS_NULL", CultureInfo.CurrentCulture), null); return R; } if (Login.Trim() != "") { TempResult = this._userCheckLoginExistence(Login.Trim()); if (TempResult.ResultType != Communication.EnFunctionResultType.ESuccess) { R = CServerHelper.sCompileFunctionResult("UserRegister", Communication.EnFunctionResultType.EError, InputParameters, TempResult.Message, TempResult.Content); return R; } } if (Email.Trim() != "") { TempResult = this._userCheckEmailExistence(Email.Trim()); if (TempResult.ResultType != Communication.EnFunctionResultType.ESuccess) { R = CServerHelper.sCompileFunctionResult("UserRegister", Communication.EnFunctionResultType.EError, InputParameters, TempResult.Message, TempResult.Content); return R; } } if (Phone.Trim() != "") { TempResult = this._userCheckPhoneExistence(Phone.Trim()); if (TempResult.ResultType != Communication.EnFunctionResultType.ESuccess) { R = CServerHelper.sCompileFunctionResult("UserRegister", Communication.EnFunctionResultType.EError, InputParameters, TempResult.Message, TempResult.Content); return R; } } CSystemUser User = new CSystemUser(CServerEnvironment.DataContext) { Email = Email, Login = Login, MobilePhone = Phone, Parent = CEmbeddedObjectsConsts.CONST_FOLDER_USERS_KEY, Passhash = CSecurityHelper.sGeneratePasshash(Login.Trim(), Password.Trim()), Status = EnMetaobjectStatus.EEnabled, System = false, SystemType = EnSystemUserType.EUser, ID = Guid.NewGuid(), Key = CDatabaseSequence.sGetObjectKey(CServerEnvironment.DatabaseProvider) }; var RR = User.ObjectInsert(CServerEnvironment.DataContext); if (RR != CErrors.ERR_SUC) { R = CServerHelper.sCompileFunctionResult("UserRegister", Communication.EnFunctionResultType.EError, InputParameters, CGlobalizationHelper.sGetStringResource("ERROR_OBJECT_INSERT_UNABLE", CultureInfo.CurrentCulture), null); return R; } try { CServerEnvironment.DataContext.SubmitChanges(); } catch (Exception Exception) { R = CServerHelper.sCompileFunctionResult("UserRegister", Communication.EnFunctionResultType.EError, InputParameters, Exception.Message, null); return R; } cMenu.Metaobjects.Linq.CMetaobjectLink L = new cMenu.Metaobjects.Linq.CMetaobjectLink() { LinkedObjectKey = User.Key, LinkType = EnMetaobjectLinkType.ESecurity, LinkValue = 1, SourceObjectKey = CEmbeddedSecurityConsts.CONST_USER_GROUP_USERS_KEY }; RR = L.LinkInsert(CServerEnvironment.DataContext); if (RR != CErrors.ERR_SUC) { /// Empty resource R = CServerHelper.sCompileFunctionResult("UserRegister", Communication.EnFunctionResultType.EError, InputParameters, CGlobalizationHelper.sGetStringResource("", CultureInfo.CurrentCulture), null); return R; } try { CServerEnvironment.DataContext.SubmitChanges(); } catch (Exception Exception) { /// Empty resource return CServerHelper.sCompileFunctionResult("UserRegister", Communication.EnFunctionResultType.EError, InputParameters, Exception.Message, null); } R.Content = User; return R; }
protected CFunctionResult _callOficiant(string UserIdentity, string Passhash, Guid SessionID) { Dictionary<string, object> InputParameters = new Dictionary<string, object>(); InputParameters.Add("UserIdentity", UserIdentity); InputParameters.Add("Passhash", Passhash); InputParameters.Add("SessionID", SessionID.ToString().ToUpper()); CFunctionResult R = new CFunctionResult() { FunctionID = "CallOficiant", InputParameters = InputParameters, ResultType = Communication.EnFunctionResultType.ESuccess }; CFunctionResult UserResult = CServerHelper.sCheckUser(UserIdentity, Passhash, SessionID); if (UserResult.ResultType != Communication.EnFunctionResultType.ESuccess) { UserResult.FunctionID = "CallOficiant"; UserResult.InputParameters = InputParameters; return UserResult; } CSystemUser User = (CSystemUser)(UserResult.Content as object[])[0]; CSystemUserSession Session = (CSystemUserSession)(UserResult.Content as object[])[1]; return R; }
protected CFunctionResult _makeOrder(string UserIdentity, string Passhash, Guid SessionID, string OrderJSON) { Dictionary<string, object> InputParameters = new Dictionary<string, object>(); InputParameters.Add("UserIdentity", UserIdentity); InputParameters.Add("Passhash", Passhash); InputParameters.Add("SessionID", SessionID.ToString().ToUpper()); CFunctionResult R = new CFunctionResult() { FunctionID = "MakeOrder", InputParameters = InputParameters, ResultType = Communication.EnFunctionResultType.ESuccess }; if (OrderJSON == null) { R = CServerHelper.sCompileFunctionResult("MakeOrder", Communication.EnFunctionResultType.EError, InputParameters, CGlobalizationHelper.sGetStringResource("ERROR_INPUT_OBJECT_BAD_FORMAT", CultureInfo.CurrentCulture), null); return R; } CFunctionResult UserResult = CServerHelper.sCheckUser(UserIdentity, Passhash, SessionID); if (UserResult.ResultType != Communication.EnFunctionResultType.ESuccess) { UserResult.FunctionID = "MakeOrder"; UserResult.InputParameters = InputParameters; return UserResult; } CSystemUser User = (CSystemUser)(UserResult.Content as object[])[0]; CSystemUserSession Session = (CSystemUserSession)(UserResult.Content as object[])[1]; CMenuServiceOrder NewOrder = OrderJSON.ToDataStream().DeserializeJSONStream<CMenuServiceOrder>(typeof(CMenuServiceOrder)); if (NewOrder == null) { R = CServerHelper.sCompileFunctionResult("MakeOrder", Communication.EnFunctionResultType.EError, InputParameters, CGlobalizationHelper.sGetStringResource("ERROR_INPUT_OBJECT_BAD_FORMAT", CultureInfo.CurrentCulture), null); return R; } NewOrder.SessionKey = Session.Key; NewOrder.Key = CDatabaseSequence.sGetObjectKey(CServerEnvironment.DatabaseProvider); NewOrder.ID = Guid.NewGuid(); NewOrder.Date = DateTime.Now; var RR = NewOrder.OrderInsert(CServerEnvironment.DataContext); if (RR != CErrors.ERR_SUC) { R = CServerHelper.sCompileFunctionResult("MakeOrder", Communication.EnFunctionResultType.EError, InputParameters, CGlobalizationHelper.sGetStringResource("ERROR_ORDER_MAKE_UNABLE", CultureInfo.CurrentCulture), null); return R; } try { CServerEnvironment.DataContext.SubmitChanges(); } catch (Exception Exception) { R = CServerHelper.sCompileFunctionResult("MakeOrder", Communication.EnFunctionResultType.EError, InputParameters, Exception.Message, null); return R; } R.Content = NewOrder; return R; }
public static CFunctionResult sCheckUser(string UserIdentity, string Passhash, Guid SessionID) { CFunctionResult R = new CFunctionResult() { FunctionID = "CheckUser", ResultType = EnFunctionResultType.ESuccess }; if (UserIdentity == null || Passhash == null || SessionID == null) { R = CServerHelper.sCompileFunctionResult("CheckUser", Communication.EnFunctionResultType.EError, null, "ERROR_USER_INPUT_PARAMS_NULL", null); return R; } if (UserIdentity.Trim() == "") { R = CServerHelper.sCompileFunctionResult("CheckUser", Communication.EnFunctionResultType.EError, null, "ERROR_USER_INPUT_PARAMS_NULL", null); return R; } CSystemUser User = null; User = CSystemUser.sGetUserByLogin(UserIdentity.Trim(), CServerEnvironment.DataContext); if (User == null) { User = CSystemUser.sGetUserByEmail(UserIdentity.Trim(), CServerEnvironment.DataContext); if (User == null) User = CSystemUser.sGetUserByMobilePhone(UserIdentity.Trim(), CServerEnvironment.DataContext); } if (User == null) { R = CServerHelper.sCompileFunctionResult("CheckUser", Communication.EnFunctionResultType.EError, null, "ERROR_OBJECT_UNABLE_TO_FIND", null); return R; } var Verified = (Passhash == User.Passhash); if (!Verified) { R = CServerHelper.sCompileFunctionResult("CheckUser", Communication.EnFunctionResultType.EError, null, "ERROR_USER_BAD_IDENTITY_OR_PASS", null); return R; } CSystemUserSession Session = new CSystemUserSession() { ID = SessionID }; var RR = Session.SessionGetByID(SessionID, CServerEnvironment.DataContext); if (RR != CErrors.ERR_SUC) { R = CServerHelper.sCompileFunctionResult("CheckUser", Communication.EnFunctionResultType.EError, null, "ERROR_SESSION_NULL", null); return R; } if (Session.UserKey != User.Key) { R = CServerHelper.sCompileFunctionResult("CheckUser", Communication.EnFunctionResultType.EError, null, "ERROR_SESSION_KEYS_NOT_EQUALS", null); return R; } if (Session.DeadLine <= DateTime.Now) { R = CServerHelper.sCompileFunctionResult("CheckUser", Communication.EnFunctionResultType.EError, null, "ERROR_SESSION_DEADLINE_EXPIRES", null); return R; } if (Session.Status != EnSessionStatus.EEnabled) { R = CServerHelper.sCompileFunctionResult("CheckUser", Communication.EnFunctionResultType.EError, null, "ERROR_SESSION_NOT_ENABLED", null); return R; } var Content = new object[2]; Content[0] = User; Content[1] = Session; R.Content = Content; return R; }
protected CFunctionResult _getServiceInformation(string UserIdentity, string Passhash, Guid SessionID, Guid ServiceID) { Dictionary<string, object> InputParameters = new Dictionary<string, object>(); InputParameters.Add("UserIdentity", UserIdentity); InputParameters.Add("Passhash", Passhash); InputParameters.Add("SessionID", SessionID.ToString().ToUpper()); InputParameters.Add("ServiceID", ServiceID); CFunctionResult R = new CFunctionResult() { FunctionID = "GetServiceInformation", InputParameters = InputParameters, ResultType = Communication.EnFunctionResultType.ESuccess }; if (ServiceID == null) { R = CServerHelper.sCompileFunctionResult("GetServiceInformation", Communication.EnFunctionResultType.EError, InputParameters, CGlobalizationHelper.sGetStringResource("ERROR_OBJECT_ID_NULL", CultureInfo.CurrentCulture), null); return R; } CFunctionResult UserResult = CServerHelper.sCheckUser(UserIdentity, Passhash, SessionID); if (UserResult.ResultType != Communication.EnFunctionResultType.ESuccess) { UserResult.FunctionID = "GetServiceInformation"; UserResult.InputParameters = InputParameters; return UserResult; } CMetaobjectShortcut ServiceShortcut = new CMetaobjectShortcut(ServiceID, CServerEnvironment.DataContext); if (ServiceShortcut.Key == CDBConst.CONST_OBJECT_EMPTY_KEY) { R = CServerHelper.sCompileFunctionResult("GetServiceInformation", Communication.EnFunctionResultType.EError, InputParameters, CGlobalizationHelper.sGetStringResource("ERROR_OBJECT_UNABLE_TO_FIND", CultureInfo.CurrentCulture), null); return R; } var ServiceKey = ServiceShortcut.SourceObjectKey; CMenuService Service = new CMenuService(ServiceKey, CServerEnvironment.DataContext); if (Service.ID == Guid.Empty) { R = CServerHelper.sCompileFunctionResult("GetServiceInformation", Communication.EnFunctionResultType.EError, InputParameters, CGlobalizationHelper.sGetStringResource("ERROR_OBJECT_UNABLE_TO_FIND", CultureInfo.CurrentCulture), null); return R; } Service.GetChildren(CServerEnvironment.DataContext, false); R.Content = Service; return R; }
protected CFunctionResult _userEdit(string UserIdentity, string Passhash, Guid SessionID, string JSON) { Dictionary<string, object> InputParameters = new Dictionary<string, object>(); InputParameters.Add("UserIdentity", UserIdentity); InputParameters.Add("Passhash", Passhash); CFunctionResult R = new CFunctionResult() { FunctionID = "UserEdit", InputParameters = InputParameters, ResultType = Communication.EnFunctionResultType.ESuccess }; CFunctionResult UserResult = CServerHelper.sCheckUser(UserIdentity, Passhash, SessionID); if (UserResult.ResultType != Communication.EnFunctionResultType.ESuccess) { UserResult.FunctionID = "UserEdit"; UserResult.InputParameters = InputParameters; return UserResult; } CSystemUser User = (CSystemUser)(UserResult.Content as object[])[0]; CSystemUser UpdatedUser = JSON.ToDataStream().DeserializeJSONStream<CSystemUser>(typeof(CSystemUser)); if (UpdatedUser == null) { R = CServerHelper.sCompileFunctionResult("UserEdit", Communication.EnFunctionResultType.EError, InputParameters, CGlobalizationHelper.sGetStringResource("ERROR_USER_INPUT_PARAMS_NULL", CultureInfo.CurrentCulture), null); return R; } User.Attributes.Context = CServerEnvironment.DataContext; if (User.Key != UpdatedUser.Key || User.ID != UpdatedUser.ID) { R = CServerHelper.sCompileFunctionResult("UserEdit", Communication.EnFunctionResultType.EError, InputParameters, CGlobalizationHelper.sGetStringResource("ERROR_OBJECT_EDIT_IDENTITY_NOT_EQUAL", CultureInfo.CurrentCulture), null); return R; } CFunctionResult TempResult = null; if (User.Login.Trim() != UpdatedUser.Login.Trim()) { TempResult = this._userCheckLoginExistence(UpdatedUser.Login.Trim()); if (TempResult.ResultType != Communication.EnFunctionResultType.ESuccess && User.Key != (TempResult.Content as CSystemUser).Key) { R = CServerHelper.sCompileFunctionResult("UserEdit", Communication.EnFunctionResultType.EError, InputParameters, TempResult.Message, TempResult.Content); return R; } } if (User.Email.Trim() != UpdatedUser.Email.Trim()) { TempResult = this._userCheckEmailExistence(UpdatedUser.Email.Trim()); if (TempResult.ResultType != Communication.EnFunctionResultType.ESuccess && User.Key != (TempResult.Content as CSystemUser).Key) { R = CServerHelper.sCompileFunctionResult("UserEdit", Communication.EnFunctionResultType.EError, InputParameters, TempResult.Message, TempResult.Content); return R; } } if (User.MobilePhone.Trim() != UpdatedUser.MobilePhone.Trim()) { TempResult = this._userCheckPhoneExistence(UpdatedUser.MobilePhone.Trim()); if (TempResult.ResultType != Communication.EnFunctionResultType.ESuccess && User.Key != (TempResult.Content as CSystemUser).Key) { R = CServerHelper.sCompileFunctionResult("UserEdit", Communication.EnFunctionResultType.EError, InputParameters, TempResult.Message, TempResult.Content); return R; } } User.Address = UpdatedUser.Address; User.Email = UpdatedUser.Email; User.FirstName = UpdatedUser.FirstName; User.FullDescription = UpdatedUser.FullDescription; User.HomePhone = UpdatedUser.HomePhone; User.Login = UpdatedUser.Login; User.MobilePhone = UpdatedUser.MobilePhone; User.Name = UpdatedUser.Name; User.Photo = UpdatedUser.Photo; User.SecondName = UpdatedUser.SecondName; User.ShortDescription = UpdatedUser.ShortDescription; User.Surname = UpdatedUser.Surname; User.WorkPhone = UpdatedUser.WorkPhone; User.ObjectUpdate(CServerEnvironment.DataContext); try { CServerEnvironment.DataContext.SubmitChanges(); } catch (Exception Exception) { R = CServerHelper.sCompileFunctionResult("UserEdit", Communication.EnFunctionResultType.EError, InputParameters, Exception.Message, null); return R; } R.Content = User; return R; }