/// <summary> /// Create a new post, posted by the given account. /// </summary> /// <param name="poster"> /// The poster's account. /// </param> /// <param name="content"> /// The message's content. /// </param> /// <returns> /// A <see cref="IPostModel"/> representing the newly created message. /// </returns> /// <exception cref="AccountNotFoundException"> /// When the given account does not exist. /// </exception> public IPostModel Create(IAccountModel poster, string content) { // TODO: Move to StorageUserModel.Post try { Guid id = this.Storage.Msg.Post(poster.Id, content); // TODO: clean this up. Maybe don't use an intermediate IMessage. var message = new Message(id, poster.Id, poster.Name, string.Empty, DateTime.Now, content) { Content = content, Id = id, Date = DateTime.Now, PosterAvatar = string.Empty, PosterId = poster.Id, PosterName = poster.Name }; return(new StoragePostModel(this.StorageContext, message)); } catch (AccountNotFound ex) { throw new AccountNotFoundException(poster.Name, ex); } }
public async Task <IAccountModel?> EvaluateAccountPendingAsync(IAccountModel accountCheckCommand) { if ( string.IsNullOrEmpty(accountCheckCommand.ProfileId) || string.IsNullOrEmpty(accountCheckCommand.Id) ) { return(null); } var isCreationAllowed = await _licenseManager.EvaluateNewEntityAsync(accountCheckCommand); if (isCreationAllowed) { accountCheckCommand.SetApproval(); } else { accountCheckCommand.SetDenial(); } var approvedEntity = await _approvalsService.CreateApprovalAsync( accountCheckCommand.ToApprovalEntity() ); if (approvedEntity != null) { var accountIsCheckedEvent = approvedEntity.ToAccountModel <AccountIsCheckedEvent>(accountCheckCommand); await _publishEndpoint.Publish(accountIsCheckedEvent); return(accountIsCheckedEvent); } return(null); }
public static ProfileEntity ToNewProfileEntity(this IAccountModel accountEvent) { return(new ProfileEntity { // Properties Balance = accountEvent.Balance, Transactions = new List <TransactionSubEntity>(), // Foreign Properties ProfileId = accountEvent.ProfileId, AccountId = accountEvent.Id, // Approvable Approved = accountEvent.Approved, Pending = accountEvent.Pending, Blocked = accountEvent.Blocked, // Concurrent Host LastSequentialNumber = accountEvent.LastSequentialNumber, // Common Entity Id = Guid.NewGuid().ToString(), Created = DateTime.Now, Updated = DateTime.Now, Version = accountEvent.Version }); }
public ClientController(ILogger <ClientController> logger, IMapper mapper, IClientModel clientModel, IAccountModel accountModel) { this._logger = logger; this._mapper = mapper; _clientModel = clientModel; _accountModel = accountModel; }
public async Task UpdateAccount(IAccountModel account, CancellationToken token) { if (account == null) { return; } await account.Update(token); }
public async Task UpdateAccount(IAccountModel newAccount) { if (!await IsAccountExists()) { throw new InvalidOperationException("You cannot update not existing account!"); } await DeleteAccount(); await AddAccount(newAccount); }
public AccountListViewItemViewModel(IAccountModel model, ILocalizationService localizationService) { _localizationService = localizationService; Model = model; Title = Model.Title; TypeTitle = GetTypeTitle(model.Type, localizationService); BalanceWithCurrencySymbol = $"{Model.Balance.ToString("N2")} {Model.Currency}"; ArchiveTitle = Model.IsArchived ? _localizationService.GetTranslateByKey(Localization.InArchive) : ""; }
public async Task SaveAccount(IAccountModel newAccount, CancellationToken token) { if (newAccount == null) { return; } await newAccount.Save(token); }
public ProfileDto?AddNewProfile(IAccountModel accountModel) { if (string.IsNullOrEmpty(accountModel.ProfileId)) { return(null); } var profile = _profilesService.Create(accountModel.ToNewProfileEntity()); return(profile?.ToProfileDto()); }
// HACK - end public void SetModel(IAccountModel model) { this.AccountModel = (IAccountModel)model; // HACK this.PaymentModel = Vortx.OnePageCheckout.ObjectFactory.CreateModelFactory().CreatePaymentModel(); // HACK - end this.AccountModel.LostPasswordSent += new LostPasswordSentHandler(AccountModel_LostPasswordSent); this.AccountModel.PasswordChanged += new PasswordChangedHandler(AccountModel_PasswordChanged); }
protected void ResetCurrentAccount() { // Hack because DateTime.MinValue means "session cookie". Microsoft logic! var cookie = new HttpCookie(AccountCookie, null) { Expires = DateTime.MinValue.AddMilliseconds(1) }; this.Response.SetCookie(cookie); this.currentAccount = null; }
/// <summary> /// Creates a new list associated with the given account. /// </summary> /// <param name="account"> /// The account to be the list's owner. /// </param> /// <param name="name"> /// The list's name. /// </param> /// <param name="description"> /// The list's description. /// </param> /// <param name="isPrivate"> /// A boolean indicating whether the list is private or public. /// </param> /// <returns> /// An <see cref="IListModel"/> representing the newly created list. /// </returns> /// <exception cref="AccountNotFoundException"> /// When the account does not exist. /// </exception> public IListModel Create(IAccountModel account, string name, string description, bool isPrivate) { try { var id = this.Storage.List.Create(account.Id, name, description, isPrivate); return(this.Find(id)); } catch (AccountNotFound ex) { throw new AccountNotFoundException(name, ex); } }
/// <summary> /// Delete an account model. /// </summary> /// <param name="interfaceAccount"> /// The account model to delete. /// </param> public void Delete(IAccountModel interfaceAccount) { // TODO: fixme StorageAccountModel account = interfaceAccount as StorageAccountModel ?? this.InternalFind(interfaceAccount.Id); account.MarkDeleted(); // Should we do this now ? this.Storage.Account.Delete(account.Id); this.EntitiesMap.Remove(account.Id); }
private bool RecordExistsCheck( SqlCommand cmd, IAccountModel model, TypeOfExistenceCheck typeOfExistenceCheck, RequestType requestType ) { Int32 count0fRecordsFound = 0; bool recordExistsCheckPassed = true; DataAccessStatus dataAccessStatus = new DataAccessStatus(); SqlCommand cmdCheck = new SqlCommand(null, cmd.Connection); cmdCheck.Prepare(); if ((requestType == RequestType.Add) || (requestType == RequestType.ConfirmAdd)) { cmdCheck.CommandText = "SELECT count(*) FROM Accounts where Username = @User"; cmdCheck.Parameters.AddWithValue("@User", model.Username); } else if ((requestType == RequestType.Update) || (requestType == RequestType.Delete) || (requestType == RequestType.ConfirmDelete)) { cmdCheck.CommandText = "SELECT count(*) FROM Accounts WHERE ID = @ID"; cmdCheck.Parameters.AddWithValue("@ID", model.ID); } try { count0fRecordsFound = Convert.ToInt32(cmdCheck.ExecuteScalar()); } catch (SqlException e) { string msg = e.Message; throw e; } if ((typeOfExistenceCheck == TypeOfExistenceCheck.DoesNotExistInDB) && (count0fRecordsFound > 0)) { dataAccessStatus.Status = "Error"; recordExistsCheckPassed = false; throw new DataAccessException(dataAccessStatus); } else if ((typeOfExistenceCheck == TypeOfExistenceCheck.DoesExistInDB) && (count0fRecordsFound == 0)) { dataAccessStatus.Status = "Error"; recordExistsCheckPassed = false; throw new DataAccessException(dataAccessStatus); } return(recordExistsCheckPassed); }
public async Task AddAccount(IAccountModel account) { if (string.IsNullOrWhiteSpace(account.Email) || string.IsNullOrWhiteSpace(account.Password)) { throw new NullReferenceException("'Email' or 'Password' from account data has no value!"); } Account newAccount = new Account(account.Email); newAccount.Properties.Add("Password", account.Password); newAccount.Properties.Add("Token", account.Token); await AccountStore.Create().SaveAsync(newAccount, App.AppName); }
public bool TryFind(string name, out IAccountModel account) { try { var id = this.Storage.Account.GetId(name); account = this.Find(id); return(true); } catch (AccountNotFound) { account = null; return(false); } }
protected bool TrySetCurrentAccount(IAccountModel value) { if (this.CurrentUser.Accounts.Contains(value)) { var cookie = new HttpCookie(AccountCookie, value.Id.ToString()) { HttpOnly = true }; this.Response.SetCookie(cookie); this.currentAccount = value; return(true); } return(false); }
public ActionResult Edit(EditListViewModel editList, int edit) { if (editList.AccountIds == null) { ModelState.AddModelError("Members", "The list must contain at least one member."); return(this.View("_EditListModal", editList)); } else { // TODO: This is NOT correct. There should be *TWO* distinct methods Edit and Create. //TODO : Check whether or not currentAccount is authorized to edit this list IListModel list = null; list = edit == 0 ? this.Storage.Lists.Create( this.CurrentAccount, editList.ListName, editList.ListDescription, !editList.ListPublic) : this.Storage.Lists.Find(editList.ListId); if (list == null) { throw new HttpException((int)HttpStatusCode.NotFound, "The list doesn't exists."); } try { list.Name = editList.ListName; list.Description = editList.ListDescription; list.IsPrivate = !editList.ListPublic; list.Members.Clear(); foreach (var member in editList.AccountIds) { IAccountModel account = this.Storage.Accounts.Find(member); list.Members.Add(account); } this.Storage.SaveChanges(); return(this.RedirectToAction("Index", "Home")); } catch (Models.Storage.AccountNotFoundException ex) { if (edit == 0) { this.Storage.Lists.Delete(list); } throw new HttpException((int)HttpStatusCode.NotFound, ex.Message); } catch (Tigwi.Storage.Library.IsPersonnalList ex) { return(this.RedirectToAction("Index", "Home", new { error = ex.Message })); } } }
static void Main(string[] args) { IAbstractEcommerceFactory factory = new SqlServerEcommerceFactory(); IAccountModel accountModel = factory.AccountModel; accountModel.Create(new Account()); IProductModel productModel = factory.ProductModel; productModel.Create(new Product()); IOrderModel orderModel = factory.OrderModel; orderModel.Create(new Order()); }
public static ApprovalEntity ToApprovalEntity(this IAccountModel accountModel) { return(new ApprovalEntity { Id = Guid.NewGuid(), Created = DateTime.Now, Updated = DateTime.Now, Version = 0, AccountId = accountModel.Id.ToGuid(), ProfileId = accountModel.ProfileId, Approved = accountModel.Approved, Pending = accountModel.Pending, Blocked = accountModel.Blocked }); }
/// <summary> /// Show all the people an account is following. /// </summary> /// <returns>The resulting view.</returns> public ActionResult Following(Guid id) { try { IAccountModel account = this.Storage.Accounts.Find(id); account.PersonalList.Followers.Add(CurrentAccount); return(this.View(account)); } catch (AccountNotFoundException) { return(this.RedirectToAction("Index", "Home", new { error = "This account doesn't exist anymore!" })); } catch { return(this.RedirectToAction("Index", "Home", new { error = "Something went wrong!" })); } }
public static AccountEntity ToAccountEntity(this IAccountModel accountEvent) { return(new AccountEntity { Id = accountEvent.Id.ToGuid(), Version = accountEvent.Version, Balance = accountEvent.Balance, ProfileId = accountEvent.ProfileId, Approved = accountEvent.Approved, Pending = accountEvent.Pending, Blocked = accountEvent.Blocked, LastSequentialNumber = accountEvent.LastSequentialNumber }); }
public ProfileDto?UpdateProfile(IAccountModel accountModel) { if ( string.IsNullOrEmpty(accountModel.ProfileId) || string.IsNullOrEmpty(accountModel.Id) ) { return(null); } var updated = _profilesService.UpdatePassively(accountModel.ToNewProfileEntity()); if (updated != null || !string.IsNullOrEmpty(updated?.Id)) { return(updated.ToProfileDto()); } return(null); }
public IResponse <IAccountModel, AccountResponse> CreateAccount(IAccountModel request) { Logger.Here().Information("BGN"); using AccountContext context = accountContextFactory.Create(); context.Accounts.Add((AccountEntity)request); try { context.SaveChanges(); } catch (Exception e) { Logger.Here().Warning("Failed: " + e.Message); return(new AccountResponseBL(Constants.Response.INTERNAL_SERVER_ERROR, request, new Error { Description = e.Message })); } Logger.Here().Information("END"); return(new AccountResponseBL(request)); }
public AccountDialogViewModel(IAccountModel model) { Model = model; IsNew = Model.IsNew; Currency = Model.Currency; Currencies = new List <string> { Model.Currency }; switch (Model.Type) { case AccountType.Cash: _isCash = true; break; case AccountType.Card: _isCard = true; break; } }
public ActionResult Follow(Guid id) { try { IAccountModel account = this.Storage.Accounts.Find(id); //Todo redirect to a dedicated view IListModel list = this.Storage.Lists.Create(CurrentAccount, account.Name, "My friend " + account.Name, false); list.Members.Add(account); this.Storage.SaveChanges(); return(Json(new { ok = true })); } catch (AccountNotFoundException ex) { throw new HttpException((int)HttpStatusCode.NotFound, ex.Message); } }
public async Task <IAccountModel?> ProcessTransactionCheckedEventAsync(IAccountModel accountModel) { var existingAccount = await _accountsService.GetAccountByIdAsync(accountModel.Id.ToGuid()); if (existingAccount != null) { if (accountModel.IsBlocked()) { existingAccount.SetBlocked(); } var updatedAccount = await _accountsService.UpdateAccountAsync(existingAccount); return(updatedAccount?.ToAccountModel <AccountDto>()); } var createdAccount = await _accountsService.CreateAccountAsync(accountModel.ToAccountEntity()); return(createdAccount?.ToAccountModel <AccountDto>()); }
public async Task <IAccountModel?> EvaluateAccountRunningAsync(IAccountModel accountCheckCommand) { if ( string.IsNullOrEmpty(accountCheckCommand.ProfileId) || string.IsNullOrEmpty(accountCheckCommand.Id) ) { return(null); } var isValidState = await _licenseManager.EvaluateStateEntityAsync(accountCheckCommand); if (isValidState) { return(accountCheckCommand); } var approvalRecord = await _approvalsService.GetOneByParameterAsync( a => a != null && a.AccountId == accountCheckCommand.Id.ToGuid() ); if (approvalRecord != null) { approvalRecord.SetBlocked(); var approvedEntity = await _approvalsService.UpdateApprovalAsync( approvalRecord ); if (approvedEntity != null) { var accountIsCheckedEvent = approvedEntity.ToAccountModel <AccountIsCheckedEvent>( accountCheckCommand ); await _publishEndpoint.Publish(accountIsCheckedEvent); return(accountIsCheckedEvent); } } return(null); }
public ActionResult Edit(AccountEditViewModel editAccount) { if (ModelState.IsValid) { IAccountModel account = this.Storage.Accounts.Find(editAccount.AccountId); account.Description = editAccount.Description; //TODO : we need to do a diff between those 2 lists ... there is no way we can remove users as is ... //TODO : in the meantime, a temporary solution : account.Users.Clear(); foreach (var member in editAccount.UserIds) { IUserModel user = this.Storage.Users.Find(member); account.Users.Add(user); } this.Storage.SaveChanges(); return(this.RedirectToAction(editAccount.ReturnAction, editAccount.ReturnController)); } return(this.RedirectToAction("Index", "Home", new { error = "Invalid attributes, try again !" })); }
public ActionResult Delete(Guid id) { try { IAccountModel account = this.Storage.Accounts.Find(id); this.Storage.Accounts.Delete(account); this.Storage.SaveChanges(); if (id == CurrentAccount.Id) { CurrentAccount = CurrentUser.Accounts.ElementAt(0); } return(this.RedirectToAction("List", "Account")); } catch (AccountNotFoundException) { return(this.RedirectToAction("Index", "Home", new { error = "This account doesn't exist" })); } catch { throw new NotImplementedException("Account.Delete"); } }
protected override void OnAuthorization(AuthorizationContext filterContext) { base.OnAuthorization(filterContext); var identity = this.User.Identity; if (!identity.IsAuthenticated) { return; } try { var user = this.Storage.Users.Find(identity.Name); IAccountModel account = null; var cookie = this.Request.Cookies[AccountCookie]; if (cookie != null) { Guid accountId; if (Guid.TryParse(cookie.Value, out accountId)) { try { account = this.Storage.Accounts.Find(accountId); } catch (AccountNotFoundException) { this.ResetCurrentAccount(); } } else { this.ResetCurrentAccount(); } } if (account == null) { try { account = this.Storage.Accounts.Find(identity.Name); } catch (AccountNotFoundException) { } } this.CurrentUser = user; this.currentAccount = account; } catch (UserNotFoundException) { this.Deauthenticate(); filterContext.Result = new RedirectToRouteResult(filterContext.RouteData.Values); } if (this.CurrentUser != null && this.currentAccount != null) { return; } this.Deauthenticate(); filterContext.Result = new RedirectToRouteResult(filterContext.RouteData.Values); }
protected void ResetCurrentAccount() { // Hack because DateTime.MinValue means "session cookie". Microsoft logic! var cookie = new HttpCookie(AccountCookie, null) { Expires = DateTime.MinValue.AddMilliseconds(1) }; this.Response.SetCookie(cookie); this.currentAccount = null; }
protected bool TrySetCurrentAccount(IAccountModel value) { if (this.CurrentUser.Accounts.Contains(value)) { var cookie = new HttpCookie(AccountCookie, value.Id.ToString()) { HttpOnly = true }; this.Response.SetCookie(cookie); this.currentAccount = value; return true; } return false; }