public AccountType() { InitializeComponent(); AccountTypeViewModel atvm = new AccountTypeViewModel(); this.DataContext = atvm; }
public ActionResult AddEditAccountType(long?id, AccountTypeViewModel model) { try { if (ModelState.IsValid) { bool isNew = !id.HasValue; AccountType accountType = isNew ? new AccountType { //AddedDate = DateTime.UtcNow } : accountTypeRepository.GetAccountType(id.Value); accountType.accTypeName = model.accTypeName; if (isNew) { accountTypeRepository.SaveAccountType(accountType); } else { accountTypeRepository.UpdateAccountType(accountType); } } } catch (Exception ex) { throw ex; } return(RedirectToAction("Index")); }
public async Task <AccountTypeViewModel> EncodeAccountTypeId(AccountTypeViewModel accountType) { return(await Task.Run(() => { accountType.AccountTypeId = GuidEncoder.Encode(accountType.AccountTypeId); return accountType; })); }
public ViewAccountType() { InitializeComponent(); AccountTypeViewModel _ATVM = new AccountTypeViewModel(); _ATVM.GetAccountTypeList(); this.DataContext = _ATVM; }
public async Task <IActionResult> Put(int id, [FromBody] AccountTypeViewModel model) { model = await service.Update(id, model); if (model == null) { return(BadRequest()); } return(Ok(model)); }
public async Task <IActionResult> Post([FromBody] AccountTypeViewModel value) { value = await service.Create(value); if (value == null) { return(BadRequest()); } return(CreatedAtAction("Get", new { id = value.Id }, value)); }
public IActionResult DeleteAccountType(long id) { AccountType accountType = accountTypeRepository.GetAccountType(id); AccountTypeViewModel model = new AccountTypeViewModel { accTypeName = $"{accountType.accTypeName}" }; return(PartialView("~/Views/AccountTypes/_DeleteAccountType.cshtml", model)); }
/// <summary> /// Delete an entity. /// </summary> /// <param name="model"></param> public void Delete(AccountTypeViewModel model) { var entity = model.ToEntity(); this._AccountTypesRepository.Delete(entity); #region Commit Changes this._unitOfWork.Commit(); #endregion }
public ActionResult Create(AccountTypeViewModel model) { if (ModelState.IsValid) { var account = Mapper.Map <AccountType>(model); account.OwnerId = User.Identity.GetUserId(); _unitOfWork.AccountTypes.Add(account); _unitOfWork.Complete(); return(RedirectToAction("Index")); } return(View(model)); }
/// <summary> /// Insert new AccountType item. /// </summary> /// <param name="model">The AccountType information value.</param> /// <returns></returns> public ResultViewModel Save(AccountTypeViewModel model) { var result = new ResultViewModel(); using (TransactionScope scope = new TransactionScope()) { var accountType = _mapper.Map <AccountTypeViewModel, AccountType>(model); _unitOfWork.GetRepository <AccountType>().Add(accountType); _unitOfWork.Complete(scope); } this.ReloadCacheAccountType(); return(result); }
/// <summary> /// Update AccountType item. /// </summary> /// <param name="model">The AccountType information value.</param> /// <returns></returns> public ResultViewModel Edit(AccountTypeViewModel model) { var result = new ResultViewModel(); using (TransactionScope scope = new TransactionScope()) { var accountType = _unitOfWork.GetRepository <AccountType>().GetCache(x => x.Id == model.Id).FirstOrDefault(); accountType.TypeName = model.TypeName; _unitOfWork.GetRepository <Data.Pocos.AccountType>().Update(accountType); _unitOfWork.Complete(scope); } this.ReloadCacheAccountType(); return(result); }
public IActionResult AddEditAccountType(long?id) { AccountTypeViewModel model = new AccountTypeViewModel(); if (id.HasValue) { AccountType accountType = accountTypeRepository.GetAccountType(id.Value); if (accountType != null) { model.accTypeId = accountType.accTypeId; model.accTypeName = accountType.accTypeName; } } return(PartialView("~/Views/AccountTypes/_AddEditAccountType.cshtml", model)); }
/// <summary> /// Update an entity. /// </summary> /// <param name="model"></param> /// <returns></returns> public AccountTypeViewModel Update(AccountTypeViewModel model) { this.ThrowExceptionIfExist(model); var entity = model.ToEntity(); entity = this._AccountTypesRepository.Update(entity); #region Commit Changes this._unitOfWork.Commit(); #endregion model = entity.ToModel(); return(model); }
/// <summary> /// Throw an exception if name is exist. /// </summary> /// <param name="model">AccountType view model</param> public void ThrowExceptionIfExist(AccountTypeViewModel model) { ConditionFilter <AccountType, long> condition = new ConditionFilter <AccountType, long> { Query = (entity => entity.Name == model.Name && entity.Id != model.Id) }; var existEntity = this._AccountTypesRepository.Get(condition).FirstOrDefault(); if (existEntity != null) { throw new ItemAlreadyExistException(); } }
public ActionResult Edit(int id, AccountTypeViewModel model) { if (ModelState.IsValid) { // ensure the id is valid and belongs to this user. var accountType = _unitOfWork.AccountTypes.Get(id); if (accountType == null) { return(HttpNotFound()); } if (accountType.OwnerId != UserId) { return(new HttpUnauthorizedResult("You are not authorized to edit this record.")); } Mapper.Map(model, accountType); _unitOfWork.AccountTypes.Update(accountType); _unitOfWork.Complete(); return(RedirectToAction("Index")); } return(View(model)); }
public IActionResult Edit([FromBody] AccountTypeViewModel model) { return(Ok(_accountType.Edit(model))); }
public IActionResult Save([FromBody] AccountTypeViewModel model) { return(Ok(_accountType.Save(model))); }