/// <summary> /// Deletes the asynchronous. /// </summary> /// <param name="entity">The entity.</param> /// <returns></returns> public async Task<SaveResult> DeleteAsync(MSTProductDto entity) { SaveResult result = SaveResult.FAILURE; try { using (FailureAnalysisEntities context = new FailureAnalysisEntities()) { var assembly = context.MST_Product.Single(x => x.Id == entity.Id && x.IsDeleted == false); assembly.IsDeleted = true; context.Entry<MST_Product>(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> /// Adds the asynchronous. /// </summary> /// <param name="entity">The entity.</param> /// <returns></returns> public async Task<SaveResult> AddAsync(MSTProductDto entity) { SaveResult result = SaveResult.FAILURE; try { using (FailureAnalysisEntities context = new FailureAnalysisEntities()) { MST_Product add = context.MST_Product.Create(); add.Description = entity.Description; add.MainPerson = entity.MainPerson; add.SecondaryPerson = entity.SecondaryPerson; add.TertiaryPerson = entity.TertiaryPerson; add.LabSiteId = entity.LabSiteId; add.Name = entity.Name; add.IsDeleted = false; add.LastUpdatedBy = entity.LastUpdatedBy; add.LastUpdate = DateTime.Now; context.Entry<MST_Product>(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(ProductViewModel viewmodel) { if (ModelState.IsValid) { MSTProductDto bu = new MSTProductDto { Name = viewmodel.Name, Description = viewmodel.Description, MainPerson = viewmodel.MainPerson, SecondaryPerson = viewmodel.SecondaryPerson, TertiaryPerson = viewmodel.TertiaryPerson, LabSiteId = viewmodel.LabSiteId, LastUpdatedBy = CurrentName }; var result = await ProductRep.AddAsync(bu); if (result == Model.SaveResult.SUCCESS) return RedirectToAction("Index"); } return View(viewmodel); }
/// <summary> /// Updates the asynchronous. /// </summary> /// <param name="entity">The entity.</param> /// <returns></returns> public async Task<SaveResult> UpdateAsync(MSTProductDto entity) { SaveResult result = SaveResult.FAILURE; try { using (FailureAnalysisEntities context = new FailureAnalysisEntities()) { var product = context.MST_Product.Single(x => x.Id == entity.Id && x.IsDeleted == false); product.Name = entity.Name; product.MainPerson = entity.MainPerson; product.SecondaryPerson = entity.SecondaryPerson; product.TertiaryPerson = entity.TertiaryPerson; product.LabSiteId = entity.LabSiteId; product.IsDeleted = entity.IsDeleted; product.Description = entity.Description; product.LastUpdatedBy = entity.LastUpdatedBy; product.LastUpdate = DateTime.Now; context.Entry<MST_Product>(product).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> Edit(int id, ProductViewModel viewmodel) { if (ModelState.IsValid) { MSTProductDto product = new MSTProductDto { Id = id, Name = viewmodel.Name, Description = viewmodel.Description, MainPerson = viewmodel.MainPerson, TertiaryPerson = viewmodel.TertiaryPerson, SecondaryPerson = viewmodel.SecondaryPerson, LabSiteId = viewmodel.LabSiteId, LastUpdatedBy = CurrentName, }; //update product to server var result = await ProductRep.UpdateAsync(product); if (result == Model.SaveResult.SUCCESS) return RedirectToAction("Index"); } return View(viewmodel); }