/// <summary> /// Adds the asynchronous. /// </summary> /// <param name="entity">The entity.</param> /// <returns></returns> public async Task<SaveResult> AddAsync(MSTPriorityDto entity) { SaveResult result = SaveResult.FAILURE; try { using (FailureAnalysisEntities context = new FailureAnalysisEntities()) { MST_Priority add = context.MST_Priority.Create(); add.Description = entity.Description; add.Name = entity.Name; add.IsDeleted = false; add.LastUpdatedBy = entity.LastUpdatedBy; add.LastUpdate = DateTime.Now; context.Entry<MST_Priority>(add).State = System.Data.Entity.EntityState.Added; result = await context.SaveChangesAsync() > 0 ? SaveResult.SUCCESS : SaveResult.FAILURE; } } catch (Exception ex) { _logService.Error(ex.Message, ex); result = SaveResult.FAILURE; } return result; }
/// <summary> /// Deletes the asynchronous. /// </summary> /// <param name="entity">The entity.</param> /// <returns></returns> public async Task<SaveResult> DeleteAsync(MSTPriorityDto entity) { SaveResult result = SaveResult.FAILURE; try { using (FailureAnalysisEntities context = new FailureAnalysisEntities()) { var priority = context.MST_Priority.Single(x => x.Id == entity.Id && x.IsDeleted == false); priority.IsDeleted = true; priority.LastUpdate = DateTime.Now; priority.LastUpdatedBy = entity.LastUpdatedBy; context.Entry<MST_Priority>(priority).State = System.Data.Entity.EntityState.Modified; result = await context.SaveChangesAsync() > 0 ? SaveResult.SUCCESS : SaveResult.FAILURE; } } catch (Exception ex) { _logService.Error(ex.Message, ex); result = SaveResult.FAILURE; } return result; }
public async Task<ActionResult> Create(MSTViewModel viewmodel) { if (ModelState.IsValid) { MSTPriorityDto priority = new MSTPriorityDto { Name = viewmodel.Name, Description = viewmodel.Description, LastUpdatedBy = CurrentName }; var result = await PriorityRepository.AddAsync(priority); if (result == Model.SaveResult.SUCCESS) return RedirectToAction("Index"); } return View(viewmodel); }