public Loyalty NewLoyalty(Loyalty data) { _rightsManager.CheckRole(AccountRole.Admin); var loyalAcc = UserContext.Accounts.GetOrFail(data.LoyalName);//_userManager.FindById(data.LoyalName); Try.Condition(loyalAcc.Role.IsCompany(), $"{loyalAcc.Login} не является компанией"); var check = UserContext.Data.Loyalties.Where(x => x.LoyalName == loyalAcc.Login && x.Insurance == data.Insurance); Try.Condition(!check.Any(), $"Компания уже обслуживает данную страховку"); Try.Condition(data.MinLevel < 4 && data.MinLevel > 0, $"Значения MinLevel разрешены в диапазоне [1:3]"); var loyalty = new Loyalty(loyalAcc, data.Insurance); loyalty.MinLevel = data.MinLevel; UserContext.Data.Loyalties.Add(loyalty); UserContext.Data.SaveChanges(); var issuerAcc = GetIssuerFromType(data.Insurance); UserContext.AddGameEvent(issuerAcc.Login, GameEventType.Insurance, $"Вашу страховку теперь обслуживает {loyalAcc.DisplayName}", true); UserContext.AddGameEvent(loyalAcc.Login, GameEventType.Insurance, $"Вы начали обслуживать страховку {loyalty.Insurance}", true); return(loyalty); }
private void ProlongInsurance() { foreach (var kv in _associations) { var corp = UserContext.Accounts.Get(kv.Key); if (corp == null) { continue; //Corp not found in DB } var totalPrice = 0; var holders = GetInsuranceHolders(kv.Key).OrderByDescending(x => x.InsuranceLevel).ToList(); foreach (var holder in holders) { var effectivePrice = (int)UserContext.Constants.GetInsuranceCost(holder.Insurance, holder.InsuranceLevel); if (corp.InsurancePoints >= effectivePrice) { totalPrice += effectivePrice; corp.InsurancePoints -= effectivePrice; UserContext.AddGameEvent(holder.UserLogin, GameEventType.Index, $"Ваша страховка {holder.Insurance} продлена", true); } else { var userAccount = UserContext.Accounts.GetOrFail(holder.UserLogin); RemoveInsuranceHolder_Checked(userAccount, corp); } } UserContext.AddGameEvent(corp.Login, GameEventType.Index, $"Продлены страховки, потрачено {totalPrice} очков", true); //UserContext.Accounts.Update(corp); } }
public Account Registration(RegistrationClientData clientData) { _rightsManager.CheckRole(AccountRole.Admin); var existing = Get(clientData.Login); if (clientData.Status != AccountStatus.Blocked) { clientData.Status = AccountStatus.Active; } if (existing != null) { return(SetAccountProperties(clientData)); } var newUser = new Account(clientData.Login, AccountRole.Person); var result = _userManager.Create(newUser, clientData.Password); Try.Condition(result.Succeeded, $"Не удалось создать счет {clientData.Login}, {result.Errors.FirstOrDefault()}"); UserContext.Data.SaveChanges(); UserContext.AddGameEvent(clientData.Login, GameEventType.None, $"Аккаунт создан"); return(SetAccountProperties(clientData)); }
public void SetAccessChangeGameEvents(Account slave, Account master, AccountAccessRoles role) { UserContext.AddGameEvent(slave.Login, GameEventType.Rights, $"Доступ {master.DisplayName} к вашему счету изменен на {role}"); UserContext.AddGameEvent(master.Login, GameEventType.Rights, $"Доступ над счетом {slave.DisplayName} изменен на {role}"); }
public Account SetAccountProperties(RegistrationClientData data) { UserContext.Rights.CheckRole(AccountRole.Admin); var editAccount = UserContext.Accounts.GetOrFail(data.Login); if (data.Role != null && data.Role != editAccount.Role) { editAccount.Role = data.Role.Value; UserContext.AddGameEvent(editAccount.Login, GameEventType.Rights, $"Изменен тип счета на {editAccount.Role}"); } if (data.Status != null && data.Status != editAccount.Status) { editAccount.Status = data.Status.Value; UserContext.AddGameEvent(editAccount.Login, GameEventType.Rights, $"Изменен статус счета на {editAccount.Status}"); } if (!String.IsNullOrEmpty(data.Fullname)) { editAccount.Fullname = data.Fullname; } if (!String.IsNullOrEmpty(data.Email)) { editAccount.Email = data.Email; } if (!String.IsNullOrEmpty(data.ParentID)) { editAccount.ParentID = data.ParentID; } if (!String.IsNullOrEmpty(data.Alias)) { editAccount.Alias = data.Alias; } editAccount.Cash = data.Cash ?? editAccount.Cash; if (data.Insurance != null && data.InsuranceLevel != null) { editAccount.Insurance = data.Insurance.Value; editAccount.InsuranceLevel = editAccount.Insurance.SetLevel(data.InsuranceLevel); } if (!String.IsNullOrEmpty(data.Password)) { _userManager.NewPassword(editAccount.Login, data.Password); } AddWorkPlace(editAccount, data); UserContext.Data.SaveChanges(); return(editAccount); }
public void Implant(ImplantClientData data) { var receiverAcc = UserContext.Accounts.GetOrFail(data.Receiver, data.ReceiverPass); var sellerAcc = UserContext.Accounts.GetOrFail(data.Seller); var parentAcc = UserContext.Accounts.Get(sellerAcc.ParentID) ?? sellerAcc; _rightsManager.CheckForAccessOverSlave(sellerAcc, AccountAccessRoles.Withdraw); Try.Condition(parentAcc.Role.IsCompany(), $"Продавать импланты может только компания"); Try.Condition(receiverAcc.Role == AccountRole.Person, $"Получать импланты может только персона"); int indexCost = data.Index; if (receiverAcc.Insurance == InsuranceType.SuperVip || parentAcc == UserContext.Insurances.GetIssuerFromType(receiverAcc.Insurance)) { var discount = UserContext.Constants.GetDiscount(receiverAcc.EffectiveLevel); indexCost = (int)Math.Ceiling(indexCost * (1 - discount)); } Try.Condition(parentAcc.Index >= indexCost, $"Недостаточно индекса"); data.Description = ParseImplantDescription(data.Description, indexCost > 0); var tdata = new TransferClientData(receiverAcc.Login, sellerAcc.Login, data.Price) { Description = data.Description }; var trList = P2BTransfer(receiverAcc, sellerAcc, tdata); using (var dbTransact = UserContext.Data.Database.BeginTransaction()) { UserContext.Data.BeginFastSave(); trList.ForEach(TransactiontoDb); parentAcc.Index -= indexCost; dbTransact.Commit(); } if (indexCost > 0) { if (parentAcc != sellerAcc) { UserContext.AddGameEvent(parentAcc.Login, GameEventType.Index, $"Имплант за {indexCost} индекса установлен магазином {sellerAcc.Fullname}", true); } UserContext.AddGameEvent(sellerAcc.Login, GameEventType.Index, $"Имплант за {indexCost} индекса установлен {receiverAcc.Fullname}", true); UserContext.AddGameEvent(receiverAcc.Login, GameEventType.Index, $"Получен имплант от {sellerAcc.Fullname}", true); } }
private void SetInsuranceHolder_Checked(Account userAccount, int level, InsuranceType t, bool isStolen = false) { Try.Condition((userAccount.Role & AccountRole.Person) > 0, $"Только персоны могут быть держателями страховки"); var oldIssuer = GetIssuerFromType(userAccount.Insurance); var newIssuer = GetIssuerFromType(t); if (!isStolen) { var price = (int)UserContext.Constants.GetInsuranceCost(t, level); var priceOld = (int)UserContext.Constants.GetInsuranceCost(t, userAccount.InsuranceLevel); if (userAccount.Insurance == t) { price = Math.Max(0, price - priceOld); } Try.Condition(newIssuer.InsurancePoints >= price, $"Не хватает очков страховки"); newIssuer.InsurancePoints -= price; UserContext.Accounts.Update(newIssuer); var txtverb = userAccount.Insurance == t ? "изменение" : "выдачу"; UserContext.AddGameEvent(newIssuer.Login, GameEventType.Index, $"Потрачено {price} очков на {txtverb} страховки {userAccount.DisplayName}", true); } //Отменить старую страховку, если была if (oldIssuer != null && userAccount.Insurance != t) { UserContext.AddGameEvent(oldIssuer.Login, GameEventType.Insurance, $"{userAccount.DisplayName} отказался от вашей страховки", true); UserContext.AddGameEvent(userAccount.Login, GameEventType.Insurance, $"Вы отказались от страховки {t}", true); } userAccount.Insurance = t; userAccount.InsuranceLevel = level; UserContext.Accounts.Update(userAccount); //if(!isStolen) // UserContext.AddGameEvent(newIssuer.Login, GameEventType.Insurance, // $"Выдана страховка {userAccount.DisplayName}" + // $"уровня {userAccount.InsuranceLevel}"); UserContext.AddGameEvent(userAccount.Login, GameEventType.Insurance, $"Выдана страховка {userAccount.Insurance} " + $"уровня {userAccount.InsuranceLevel}", true); UpdateInsuranceInAlice(userAccount); }
private void RemoveInsuranceHolder_Checked(Account userAccount, Account companyAccount) { userAccount.Insurance = InsuranceType.None; userAccount.InsuranceLevel = 1; UserContext.Accounts.Update(userAccount); UserContext.AddGameEvent(userAccount.Login, GameEventType.Insurance, $"{companyAccount.DisplayName} отменила вашу страховку", true); UserContext.AddGameEvent(companyAccount.Login, GameEventType.Insurance, $"Отменена страховка {userAccount.DisplayName}", true); UpdateInsuranceInAlice(userAccount); }
private void RemoveStolenInsurances() { var holders = UserContext.Data.Accounts.Where(x => x.InsuranceHidden).ToList(); foreach (var holder in holders) { UserContext.AddGameEvent(holder.Login, GameEventType.Index, $"{holder.Insurance} отменила вашу страховку", true); holder.Insurance = InsuranceType.None; holder.InsuranceLevel = 1; holder.InsuranceHidden = false; UserContext.Accounts.Update(holder); } }
public Account SetAccountIndex(AccIndexClientData data) { CheckRole(AccountRole.Admin); var editAccount = UserContext.Accounts.GetOrFail(data.Login); editAccount.Index = data.Index; editAccount.InsurancePoints = data.InsurancePoints; UserContext.Accounts.Update(editAccount); UserContext.AddGameEvent(editAccount.Login, GameEventType.Index, $"Задан новый индекс {editAccount.Index} и очки страховки {editAccount.InsurancePoints}"); return(editAccount); }
public Account CutAccountIndex(string login, int index) { CheckRole(AccountRole.Master); var editAccount = UserContext.Accounts.GetOrFail(login); Try.Condition(editAccount.Index >= index, "Недостаточно индекса"); editAccount.Index -= index; UserContext.Accounts.Update(editAccount); UserContext.AddGameEvent(editAccount.Login, GameEventType.Index, $"Списано {index} индекса"); return(editAccount); }
public void LogPaymentEvent(Payment payment, bool isDeleted = false) { if (isDeleted) { UserContext.AddGameEvent(payment.Receiver, GameEventType.None, $"Отменена зарплата от {payment.EmployerName}"); UserContext.AddGameEvent(payment.Employer, GameEventType.None, $"Отменена зарплата для {payment.ReceiverName}"); return; } UserContext.AddGameEvent(payment.Receiver, GameEventType.None, $"Назначена зарплата от {payment.EmployerName} уровня {payment.SalaryLevel}", true); UserContext.AddGameEvent(payment.Employer, GameEventType.None, $"Назначена зарплата для {payment.ReceiverName} уровня {payment.SalaryLevel}"); }
private bool BlockCharWithReason(string login, string reason) { var acc = UserContext.Accounts.Get(login); if (acc == null) { return(false); } if (acc.Status != AccountStatus.Active) { return(false); } acc.Status = AccountStatus.Blocked; UserContext.Data.SaveChanges(); UserContext.AddGameEvent(acc.Login, GameEventType.None, $"Аккаунт заблокирован, причина: {reason}"); return(true); }
public void DeleteLoyalty(int id) { _rightsManager.CheckRole(AccountRole.Admin); var loyalty = UserContext.Data.Loyalties.Find(id); Try.NotNull(loyalty, $"Can't find insurance loyalty relation with id: {id}"); UserContext.AddGameEvent(loyalty.LoyalName, GameEventType.Insurance, $"Вы перестали обслуживать страховку {loyalty.Insurance}", true); var issuerAcc = GetIssuerFromType(loyalty.Insurance); UserContext.AddGameEvent(issuerAcc.Login, GameEventType.Insurance, $"{loyalty.LoyalService.DisplayName} больше не обслуживает вашу страховку", true); UserContext.Data.Loyalties.Remove(loyalty); UserContext.Data.SaveChanges(); }
private void ResetIndexValues(SwitchCycleClientData data) { foreach (var pair in _associations) { var corp = UserContext.Accounts.Get(pair.Key); if (corp == null) { continue; //Not found in DB } var cIndex = data.Indexes.ToList().FindIndex(x => x.Key == pair.Key); if (cIndex >= 0) { corp.Index = data.Indexes[cIndex].Value; } corp.InsurancePoints = corp.Index; UserContext.Accounts.Update(corp); UserContext.AddGameEvent(corp.Login, GameEventType.Index, $"Выставлен индекс {corp.Index} и очки страховки {corp.InsurancePoints}"); } }
private void AddWorkPlace(Account acc, RegistrationClientData data) { if (String.IsNullOrEmpty(data.Workplace) || data.SalaryLevel == null) { return; } if (_regAlias.ContainsKey(data.Workplace)) { data.Workplace = _regAlias[data.Workplace]; } var workPlace = Get(data.Workplace); Try.NotNull(workPlace, $"Не удалось добавить место работы {data.Workplace}, счет {acc.Login}"); if (workPlace == null) { UserContext.AddGameEvent(acc.Login, GameEventType.None, $"Не удалось добавить место работы {data.Workplace}"); return; } var oldPayments = UserContext.Data.Payments.Where(x => x.Receiver == acc.Login).ToList(); oldPayments.ForEach(x => { UserContext.Payments.LogPaymentEvent(x, true); UserContext.Data.Payments.Remove(x); }); var payment = new Payment(workPlace, acc, data.SalaryLevel.Value); UserContext.Data.Payments.Add(payment); UserContext.Payments.LogPaymentEvent(payment); if (data.IsAdmin == true) { UserContext.Rights.SetAccountAccess_Checked(workPlace, acc, AccountAccessRoles.Admin); } }
public void ChangePassword(ChangePasswordClientData clientData) { var account = GetOrFail(clientData.Login); IdentityResult result; if (account.Login != UserContext.CurrentUser.Login) { //Only Administrators can change user account password _rightsManager.CheckRole(AccountRole.Admin); result = _userManager.NewPassword(account.Login, clientData.NewPassword); } else { result = _userManager.ChangePassword(account.Login, clientData.CurrentPassword, clientData.NewPassword); } Try.Condition(result.Succeeded, $"Ошибка обновления персонажа: {result.Errors.FirstOrDefault()}"); UserContext.AddGameEvent(account.Login, GameEventType.None, $"Изменен пароль"); }