public async Task <bool> UpdateMaterialType(MaterialTypeViewModel entity) { var result = false; using (var mediaContext = new MediaContext()) { using (var transaction = mediaContext.Database.BeginTransaction()) { try { var materialType = await mediaContext.MaterialTypes.FirstOrDefaultAsync(x => x.Id == entity.Id); materialType.Name = entity.Name; mediaContext.MaterialTypes.Add(materialType); await mediaContext.SaveChangesAsync(); result = true; transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); throw ex; } } } return(result); }
public async Task <int> AddMaterialType(MaterialTypeViewModel entity) { var result = 0; using (var mediaContext = new MediaContext()) { using (var transaction = mediaContext.Database.BeginTransaction()) { try { var materialType = new MaterialType { Name = entity.Name }; mediaContext.MaterialTypes.Add(materialType); await mediaContext.SaveChangesAsync(); result = materialType.Id; transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); throw ex; } } } return(result); }
public async Task <ActionResult> SaveModify(MaterialTypeViewModel model) { using (MaterialTypeServiceClient client = new MaterialTypeServiceClient()) { MethodReturnResult <MaterialType> result = await client.GetAsync(model.Name); if (result.Code == 0) { result.Data.MainProductQtyPerLot = model.MainProductQtyPerLot; result.Data.MainRawQtyPerLot = model.MainRawQtyPerLot; result.Data.Description = model.Description; result.Data.Editor = User.Identity.Name; result.Data.EditTime = DateTime.Now; MethodReturnResult rst = await client.ModifyAsync(result.Data); if (rst.Code == 0) { rst.Message = string.Format(FMMResources.StringResource.MaterialType_SaveModify_Success , model.Name); } return(Json(rst)); } return(Json(result)); } }
// // GET: /FMM/MaterialType/Detail public async Task <ActionResult> Detail(string key) { using (MaterialTypeServiceClient client = new MaterialTypeServiceClient()) { MethodReturnResult <MaterialType> result = await client.GetAsync(key); if (result.Code == 0) { MaterialTypeViewModel viewModel = new MaterialTypeViewModel() { Name = result.Data.Key, MainRawQtyPerLot = result.Data.MainRawQtyPerLot, MainProductQtyPerLot = result.Data.MainProductQtyPerLot, CreateTime = result.Data.CreateTime, Creator = result.Data.Creator, Description = result.Data.Description, Editor = result.Data.Editor, EditTime = result.Data.EditTime }; return(PartialView("_InfoPartial", viewModel)); } else { ModelState.AddModelError("", result.Message); } } return(PartialView("_InfoPartial")); }
public async Task <ActionResult> Save(MaterialTypeViewModel model) { using (MaterialTypeServiceClient client = new MaterialTypeServiceClient()) { MaterialType obj = new MaterialType() { Key = model.Name, MainProductQtyPerLot = model.MainProductQtyPerLot, MainRawQtyPerLot = model.MainRawQtyPerLot, Description = model.Description, Editor = User.Identity.Name, EditTime = DateTime.Now, CreateTime = DateTime.Now, Creator = User.Identity.Name }; MethodReturnResult rst = await client.AddAsync(obj); if (rst.Code == 0) { rst.Message = string.Format(FMMResources.StringResource.MaterialType_Save_Success , model.Name); } return(Json(rst)); } }
public ServiceResult AddMaterialType(MaterialTypeViewModel entity) { materialTypeRepository.Add(new MaterialType { Name = entity.Name }); return(ServiceResult.GetAddResult(uow.Commit() == 1)); }
public ServiceResult UpdateMaterialType(MaterialTypeViewModel entity) { materialTypeRepository.Update(new MaterialType { Id = entity.Id.Value, Name = entity.Name }); return(ServiceResult.GetUpdateResult(uow.Commit() == 1)); }
public async Task <MaterialTypeViewModel> GetMaterialTypeById(int id) { MaterialTypeViewModel materialType = await GetMaterialById(id); if (materialType == null) { logger.Error(NoRecordsExists); throw new ResourceNotFoundException(NoRecordsExists); } return(materialType); }
public async Task GetMaterialTypeById_ShouldThrowResourceNotFoundException() { // Arrange MaterialTypeViewModel material = null; materialTypeRepository = new MaterialTypeRepository(this.logger, material); // Act var result = await this.materialTypeRepository.GetMaterialTypeById(1); // Assert }
public async Task AddMaterialType_ShouldReturnsServiceResultIsSuccessfulFalse() { // Arrange MaterialTypeViewModel material = new MaterialTypeViewModel() { Name = "" }; materialTypeRepository = new MaterialTypeRepository(this.logger, false); // Act var result = await this.materialTypeRepository.AddMaterialType(material); // Assert Assert.AreEqual(result.IsSuccessful, false); }
public async Task <ServiceResult> UpdateLibrary(MaterialTypeViewModel entity) { var isUpdated = await materialTypeWriteRepository.UpdateMaterialType(entity); ServiceResult result = new ServiceResult(); if (!isUpdated) { result.SetFailure("Error while material library."); } else { result.SetSuccess("Material updated successfully."); } return(result); }
public ActionResult AddOrUpdate(MaterialTypeViewModel entity) { if (ModelState.IsValid) { if (entity.Id.HasValue) { TempData["result"] = materialTypeService.UpdateMaterialType(entity); } else { TempData["result"] = materialTypeService.AddMaterialType(entity); } } return(View()); }
public async Task GetMaterialTypeById_ShouldReturnMaterialTypes() { // Arrange MaterialTypeViewModel material = new MaterialTypeViewModel() { Id = 1, Name = "Paper" }; materialTypeRepository = new MaterialTypeRepository(this.logger, material); // Act var result = await this.materialTypeRepository.GetMaterialTypeById(1); // Assert Assert.AreEqual(result.Id, 1); }
public async Task UpdateLibrary_ShouldReturnsServiceResultIsSuccessfulFalse() { // Arrange MaterialTypeViewModel material = new MaterialTypeViewModel() { Id = -1, Name = "Paper" }; materialTypeRepository = new MaterialTypeRepository(this.logger, false); // Act var result = await this.materialTypeRepository.UpdateLibrary(material); // Assert Assert.AreEqual(result.IsSuccessful, false); }
public async Task <ServiceResult> AddMaterialType(MaterialTypeViewModel entity) { var id = await materialTypeWriteRepository.AddMaterialType(entity); ServiceResult result = new ServiceResult() { Id = id }; if (id < 0) { result.SetFailure("Error while inserting material."); } else { result.SetSuccess("Material added successfully."); } return(result); }
public async Task <ActionResult> Post([FromBody] MaterialTypeViewModel newMatTypeViewModel) { if (ModelState.IsValid) { MaterialType newMatType = Mapper.Map <MaterialType>(newMatTypeViewModel); newMatType.UserName = User.Identity.Name; if (newMatType.Id == 0) { _repository.AddMaterialType(newMatType); } else { _repository.UpdateMaterialType(newMatType); } if (await _repository.SaveChangesAsync()) { return(Created($"api/materialtypes/{newMatTypeViewModel.Name}", Mapper.Map <MaterialTypeViewModel>(newMatTypeViewModel))); } } return(BadRequest("Failed to save changes to database")); }
public ActionResult MaterialType(MaterialTypeViewModel model) { //验证 if (ModelState.IsValid) { //名称编码是否有重复 var db = new DbEntities <MaterialType>().SimpleClient; if (db.IsAny(mt => mt.MaterialTypeName == model.MaterialTypeName || mt.MaterialTypeNo == model.MaterialTypeNo)) { ModelState.AddModelError("MaterialTypeCode", "物资种类名称或编码已存在"); } else { if (new IdentityAuth().GetCurUserID(HttpContext, out int curUserID)) { //转换为对应实体 MaterialType entity = model.InitAddMaterialType(curUserID); if (db.Insert(entity)) { TempData["Msg"] = $"物资种类 {entity.MaterialTypeName} 添加成功"; return(RedirectToAction("TypeList", "Materials")); } else { TempData["Msg"] = "添加失败"; } } } } SetSelectListItems.Supplier(this); SetSelectListItems.MaterialType(this); return(View()); }
protected override async Task <int> AddMaterial(MaterialTypeViewModel entity) { return(isCompleted ? 1 : -1); }
public MaterialTypeRepository(ILogger logger, MaterialTypeViewModel data) : base(logger) { materialTypeViewModel = data; }
protected virtual async Task <bool> UpdateMaterialType(MaterialTypeViewModel entity) { return(await materialTypeWriteRepository.UpdateMaterialType(entity)); }
protected override async Task <bool> UpdateMaterialType(MaterialTypeViewModel entity) { return(isCompleted); }
protected virtual async Task <int> AddMaterial(MaterialTypeViewModel entity) { return(await materialTypeWriteRepository.AddMaterialType(entity)); }