public virtual async void TestDelete() { var builder = new WebHostBuilder() .UseEnvironment("Production") .UseStartup <TestStartup>(); TestServer testServer = new TestServer(builder); var client = new ApiClient(testServer.CreateClient()); client.SetBearerToken(JWTTestHelper.GenerateBearerToken()); ApplicationDbContext context = testServer.Host.Services.GetService(typeof(ApplicationDbContext)) as ApplicationDbContext; IUnitService service = testServer.Host.Services.GetService(typeof(IUnitService)) as IUnitService; var model = new ApiUnitServerRequestModel(); model.SetProperties("B"); CreateResponse <ApiUnitServerResponseModel> createdResponse = await service.Create(model); createdResponse.Success.Should().BeTrue(); ActionResponse deleteResult = await client.UnitDeleteAsync(2); deleteResult.Success.Should().BeTrue(); ApiUnitServerResponseModel verifyResponse = await service.Get(2); verifyResponse.Should().BeNull(); }
public async Task <IActionResult> Create([FromBody] UnitModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState.GetErrorMessages())); } var unitmodel = _mapper.Map <Unit>(model); int companyId = int.Parse(HttpContext.User.Claims.Where(c => c.Type == ClaimTypes.NameIdentifier).FirstOrDefault().Value); var result = await _unitService.Create(unitmodel, companyId); if (!result.Success) { return(BadRequest(new { Success = false, Message = result.Message })); } var umodel = _mapper.Map <UnitModel>(result._unit); return(Ok(new { Success = true, result = umodel })); }
public IActionResult AddEdit(ProductUnit model) { if (ModelState.IsValid) { var isValid = false; var msg = ""; var IsEdit = model.UnitId > 0; if (IsEdit) { var cate = _unitService.Get(model.UnitId); if (cate != null) { cate.UnitName = model.UnitName; cate.Description = model.Description; isValid = _unitService.Update(cate); msg = "Đã cập nhật đơn vị thành công!"; } } else { isValid = _unitService.Create(model); msg = "Đã tạo đơn vị thành công!"; } if (isValid) { ViewBag.Msg = msg; ModelState.Remove("InvalidAuth"); if (!IsEdit) { model = new ProductUnit(); } } else { ModelState.AddModelError("InvalidAuth", "Đã có lỗi xảy ra, liên hệ IT."); } return(View(model)); } return(View(model)); }
public ActionResult Create(UnitViewModel vm) { Unit pt = vm.Unit; if (ModelState.IsValid) { pt.CreatedDate = DateTime.Now; pt.ModifiedDate = DateTime.Now; pt.CreatedBy = User.Identity.Name; pt.ModifiedBy = User.Identity.Name; pt.ObjectState = Model.ObjectState.Added; _UnitService.Create(pt); try { _unitOfWork.Save(); } catch (Exception ex) { string message = _exception.HandleException(ex); ModelState.AddModelError("", message); return(View(pt)); } LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel { DocTypeId = new DocumentTypeService(_unitOfWork).FindByName(MasterDocTypeConstants.Unit).DocumentTypeId, DocNo = pt.UnitName, ActivityType = (int)ActivityTypeContants.Added, })); return(RedirectToAction("Create").Success("Data saved successfully")); } // PrepareViewBag(); return(View(vm)); }
public ActionResult <OutputDtoAddUnit> Post([FromBody] InputDtoAddUnit inputDtoAddUnit) { return(Ok(_unitService.Create(inputDtoAddUnit))); }
public async Task <IActionResult> CreateUnit([FromBody] UnitsCreateOrUpdateRequestViewModel viewModel) => await HandleResultAsync(() => _unitService.Create(viewModel));