/// <summary> /// Deletes the asynchronous. /// </summary> /// <param name="entity">The entity.</param> /// <returns></returns> public async Task<SaveResult> DeleteAsync(MSTServiceDto entity) { SaveResult result = SaveResult.FAILURE; try { using (FailureAnalysisEntities context = new FailureAnalysisEntities()) { var assembly = context.MST_Services.Single(x => x.Id == entity.Id && x.IsDeleted == false); assembly.IsDeleted = true; context.Entry<MST_Services>(assembly).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; }
/// <summary> /// Updates the asynchronous. /// </summary> /// <param name="entity">The entity.</param> /// <returns></returns> public async Task<SaveResult> UpdateAsync(MSTServiceDto entity) { SaveResult result = SaveResult.FAILURE; try { using (FailureAnalysisEntities context = new FailureAnalysisEntities()) { var service = context.MST_Services.Single(x => x.Id == entity.Id && x.IsDeleted == false); service.Name = entity.Name; service.IsDeleted = entity.IsDeleted; service.Description = entity.Description; service.LastUpdatedBy = entity.LastUpdatedBy; service.LastUpdate = DateTime.Now; context.Entry<MST_Services>(service).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; }
/// <summary> /// Adds the asynchronous. /// </summary> /// <param name="entity">The entity.</param> /// <returns></returns> public async Task<SaveResult> AddAsync(MSTServiceDto entity) { SaveResult result = SaveResult.FAILURE; try { using (FailureAnalysisEntities context = new FailureAnalysisEntities()) { MST_Services add = context.MST_Services.Create(); add.Description = entity.Description; add.Name = entity.Name; add.IsDeleted = false; add.LastUpdatedBy = entity.LastUpdatedBy; add.LastUpdate = DateTime.Now; context.Entry<MST_Services>(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; }
public async Task<ActionResult> Create(MSTViewModel viewmodel) { if (ModelState.IsValid) { MSTServiceDto service = new MSTServiceDto { Name = viewmodel.Name, Description = viewmodel.Description, LastUpdatedBy = CurrentName }; var result = await ServiceRepository.AddAsync(service); if (result == Model.SaveResult.SUCCESS) return RedirectToAction("Index"); } return View(viewmodel); }