public void Delete(Account accountToDelete) { var originalAccount = Get(accountToDelete.Id); _entities.DeleteObject(originalAccount); _entities.SaveChanges(); }
public Account Create(Account accountToCreate) { _entities.AddToAccountSet(accountToCreate); _entities.SaveChanges(); return accountToCreate; }
public AccountViewModel(Account account) { //creating the elements for account type dropdown list var types = Enum.GetNames(typeof(AccountType)); Account = account; Types = new SelectList(types, Account.Type); }
public Account Update(Account accountToUpdate) { var originalAccount = Get(accountToUpdate.Id); _entities.ApplyCurrentValues(originalAccount.EntityKey.EntitySetName, accountToUpdate); _entities.SaveChanges(); return accountToUpdate; }
public bool DeleteAccount(Account accountToDelete) { try { _repository.Delete(accountToDelete); } catch { return false; } return true; }
public bool ValidateAccount(Account accountToValidate) { //convert null values to empty strings accountToValidate.Name = accountToValidate.Name ?? ""; accountToValidate.Address = accountToValidate.Address ?? ""; accountToValidate.Description = accountToValidate.Description ?? ""; if (accountToValidate.Name.Trim().Length == 0) _validationDictionary.AddError("Name", "Name is required."); if (accountToValidate.Address.Trim().Length == 0) _validationDictionary.AddError("Address", "Address is required."); if (accountToValidate.Description.Trim().Length == 0) _validationDictionary.AddError("Description", "Description is required."); return _validationDictionary.IsValid; }
public bool EditAccount(Account accountToEdit) { // Validation logic if (!ValidateAccount(accountToEdit)) return false; // Database logic try { _repository.Update(accountToEdit); } catch { return false; } return true; }
public bool CreateAccount(Account accountToCreate) { // Validation logic if (!ValidateAccount(accountToCreate)) return false; // Database logic try { _repository.Create(accountToCreate); } catch { return false; } return true; }
/// <summary> /// Create a new Account object. /// </summary> /// <param name="id">Initial value of the Id property.</param> /// <param name="name">Initial value of the Name property.</param> /// <param name="address">Initial value of the Address property.</param> /// <param name="description">Initial value of the Description property.</param> /// <param name="type">Initial value of the Type property.</param> public static Account CreateAccount(global::System.Int32 id, global::System.String name, global::System.String address, global::System.String description, global::System.String type) { Account account = new Account(); account.Id = id; account.Name = name; account.Address = address; account.Description = description; account.Type = type; return account; }
/// <summary> /// Deprecated Method for adding a new object to the AccountSet EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToAccountSet(Account account) { base.AddObject("AccountSet", account); }
public ActionResult Delete(Account account) { if (!_accountService.DeleteAccount(account)) return View(account); return RedirectToAction("Index"); }