public virtual void ValidateVM() { var dbContext = DbContext(GetCurrentMethod()); var serviceProvider = GetServiceProviderMock(dbContext).Object; LossEventCategoryFacade facade = new LossEventCategoryFacade(serviceProvider, dbContext); var data = new LossEventCategoryViewModel(); var validateService = new ValidateService(serviceProvider); Assert.ThrowsAny <ServiceValidationException>(() => validateService.Validate(data)); data.LossEvent = new Lib.ViewModels.Master.LossEvent.LossEventViewModel(); Assert.ThrowsAny <ServiceValidationException>(() => validateService.Validate(data)); }
public void Test_Validate_Should_Return_Errors() { // Arrange var ValidateService = new ValidateService(); var testClass = new TestClassWithAttrs(); // Act var errors = ValidateService.Validate(testClass); // Assert Assert.AreSame(testClass, errors.Object); Assert.AreEqual(10, errors.Errors.Length); CollectionAssert.AreEquivalent( new[] { new ValidationError("staticproperty", "Static_Property"), new ValidationError("publicproperty", "Public_Property"), new ValidationError("internalproperty", "Internal_Property"), new ValidationError("protectedproperty", "Protected_Property"), new ValidationError("privateproperty", "Private_Property"), new ValidationError("staticmethod", "Static_Method"), new ValidationError("publicmethod", "Public_Method"), new ValidationError("internalmethod", "Internal_Method"), new ValidationError("protectedmethod", "Protected_Method"), new ValidationError("privatemethod", "Private_Method") }, errors.Errors); }
public async Task <IActionResult> Post([FromBody] DeliveryOrderViewModel viewModel) { identityService.Token = Request.Headers["Authorization"].First().Replace("Bearer ", ""); identityService.Username = User.Claims.Single(p => p.Type.Equals("username")).Value; ValidateService validateService = (ValidateService)facade.serviceProvider.GetService(typeof(ValidateService)); try { validateService.Validate(viewModel); DeliveryOrder model = mapper.Map <DeliveryOrder>(viewModel); int result = await facade.Create(model, identityService.Username); Dictionary <string, object> Result = new ResultFormatter(ApiVersion, General.CREATED_STATUS_CODE, General.OK_MESSAGE) .Ok(); return(Created(String.Concat(Request.Path, "/", 0), Result)); } catch (ServiceValidationExeption e) { Dictionary <string, object> Result = new ResultFormatter(ApiVersion, General.BAD_REQUEST_STATUS_CODE, General.BAD_REQUEST_MESSAGE) .Fail(e); return(BadRequest(Result)); } catch (Exception e) { Dictionary <string, object> Result = new ResultFormatter(ApiVersion, General.INTERNAL_ERROR_STATUS_CODE, e.Message) .Fail(); return(StatusCode(General.INTERNAL_ERROR_STATUS_CODE, Result)); } }
public override async Task <ActionResult> Post([FromBody] COAViewModel viewModel) { try { VerifyUser(); ValidateService.Validate(viewModel); COAModel model = Mapper.Map <COAModel>(viewModel); Transfrom(model); await Service.CreateAsync(model); Dictionary <string, object> Result = new ResultFormatter(ApiVersion, General.CREATED_STATUS_CODE, General.OK_MESSAGE) .Ok(); return(Created(String.Concat(Request.Path, "/", 0), Result)); } catch (ServiceValidationException e) { Dictionary <string, object> Result = new ResultFormatter(ApiVersion, General.BAD_REQUEST_STATUS_CODE, General.BAD_REQUEST_MESSAGE) .Fail(e); return(BadRequest(Result)); } catch (Exception e) { Dictionary <string, object> Result = new ResultFormatter(ApiVersion, General.INTERNAL_ERROR_STATUS_CODE, e.Message) .Fail(); return(StatusCode(General.INTERNAL_ERROR_STATUS_CODE, Result)); } }
public async Task <ActionResult> Post([FromBody] PurchasingDocumentAcceptanceViewModel viewModel) { this.identityService.Token = Request.Headers["Authorization"].First().Replace("Bearer ", ""); this.identityService.Username = User.Claims.Single(p => p.Type.Equals("username")).Value; ValidateService validateService = (ValidateService)purchasingDocumentExpeditionFacade.serviceProvider.GetService(typeof(ValidateService)); try { validateService.Validate(viewModel); await purchasingDocumentExpeditionFacade.PurchasingDocumentAcceptance(viewModel, this.identityService.Username); return(NoContent()); } catch (ServiceValidationExeption e) { Dictionary <string, object> Result = new ResultFormatter(ApiVersion, General.BAD_REQUEST_STATUS_CODE, General.BAD_REQUEST_MESSAGE) .Fail(e); return(BadRequest(Result)); } catch (Exception e) { Dictionary <string, object> Result = new ResultFormatter(ApiVersion, General.INTERNAL_ERROR_STATUS_CODE, e.Message) .Fail(); return(StatusCode(General.INTERNAL_ERROR_STATUS_CODE, Result)); } }
public async Task <IActionResult> Put([FromRoute] int id, [FromBody] ExternalPurchaseOrderViewModel vm) { identityService.Username = User.Claims.Single(p => p.Type.Equals("username")).Value; ExternalPurchaseOrder m = _mapper.Map <ExternalPurchaseOrder>(vm); ValidateService validateService = (ValidateService)_facade.serviceProvider.GetService(typeof(ValidateService)); try { validateService.Validate(vm); int result = await _facade.Update(id, m, identityService.Username); return(NoContent()); } catch (ServiceValidationExeption e) { Dictionary <string, object> Result = new ResultFormatter(ApiVersion, General.BAD_REQUEST_STATUS_CODE, General.BAD_REQUEST_MESSAGE) .Fail(e); return(BadRequest(Result)); } catch (Exception e) { Dictionary <string, object> Result = new ResultFormatter(ApiVersion, General.INTERNAL_ERROR_STATUS_CODE, e.Message) .Fail(); return(StatusCode(General.INTERNAL_ERROR_STATUS_CODE, Result)); } }
public void Should_Exception_ValidationVM() { var repoMock = new Mock <IDyeingPrintingAreaInputRepository>(); var movementRepoMock = new Mock <IDyeingPrintingAreaMovementRepository>(); var summaryRepoMock = new Mock <IDyeingPrintingAreaSummaryRepository>(); var sppRepoMock = new Mock <IDyeingPrintingAreaInputProductionOrderRepository>(); var serviceProvider = GetServiceProvider(repoMock.Object, movementRepoMock.Object, summaryRepoMock.Object, sppRepoMock.Object).Object; var service = GetService(serviceProvider); var vm = new InputInspectionMaterialViewModel(); var validateService = new ValidateService(serviceProvider); Assert.ThrowsAny <ServiceValidationException>(() => validateService.Validate(vm)); vm.Date = DateTimeOffset.UtcNow.AddDays(-1); vm.InspectionMaterialProductionOrders = new List <InputInspectionMaterialProductionOrderViewModel>() { new InputInspectionMaterialProductionOrderViewModel() }; validateService = new ValidateService(serviceProvider); Assert.ThrowsAny <ServiceValidationException>(() => validateService.Validate(vm)); vm.Date = DateTimeOffset.UtcNow.AddDays(3); vm.InspectionMaterialProductionOrders = new List <InputInspectionMaterialProductionOrderViewModel>() { new InputInspectionMaterialProductionOrderViewModel() }; validateService = new ValidateService(serviceProvider); Assert.ThrowsAny <ServiceValidationException>(() => validateService.Validate(vm)); vm.Date = DateTimeOffset.UtcNow.AddHours(-2); vm.InspectionMaterialProductionOrders = new List <InputInspectionMaterialProductionOrderViewModel>() { new InputInspectionMaterialProductionOrderViewModel() { ProductionOrder = new ProductionOrder() } }; validateService = new ValidateService(serviceProvider); Assert.ThrowsAny <ServiceValidationException>(() => validateService.Validate(vm)); vm.Date = DateTimeOffset.UtcNow.AddHours(2); vm.InspectionMaterialProductionOrders = new List <InputInspectionMaterialProductionOrderViewModel>() { new InputInspectionMaterialProductionOrderViewModel() { ProductionOrder = new ProductionOrder() } }; validateService = new ValidateService(serviceProvider); Assert.ThrowsAny <ServiceValidationException>(() => validateService.Validate(vm)); vm.Id = 1; validateService = new ValidateService(serviceProvider); Assert.ThrowsAny <ServiceValidationException>(() => validateService.Validate(vm)); }
public void Should_Exception_ValidationVM() { var repoMock = new Mock <IDyeingPrintingAreaInputRepository>(); var movementRepoMock = new Mock <IDyeingPrintingAreaMovementRepository>(); var summaryRepoMock = new Mock <IDyeingPrintingAreaSummaryRepository>(); var outputRepoMock = new Mock <IDyeingPrintingAreaOutputRepository>(); var productionOrderRepoMock = new Mock <IDyeingPrintingAreaInputProductionOrderRepository>(); var outputSPPRepoMock = new Mock <IDyeingPrintingAreaOutputProductionOrderRepository>(); var serviceProvider = GetServiceProvider(repoMock.Object, movementRepoMock.Object, summaryRepoMock.Object, outputRepoMock.Object, productionOrderRepoMock.Object, outputSPPRepoMock.Object).Object; var service = GetService(serviceProvider); var vm = new InputAvalTransformationViewModel(); var validateService = new ValidateService(serviceProvider); Assert.ThrowsAny <ServiceValidationException>(() => validateService.Validate(vm)); vm.Date = DateTimeOffset.UtcNow.AddDays(-1); validateService = new ValidateService(serviceProvider); Assert.ThrowsAny <ServiceValidationException>(() => validateService.Validate(vm)); vm.Date = DateTimeOffset.UtcNow.AddDays(3); validateService = new ValidateService(serviceProvider); Assert.ThrowsAny <ServiceValidationException>(() => validateService.Validate(vm)); vm.Date = DateTimeOffset.UtcNow.AddHours(-2); validateService = new ValidateService(serviceProvider); Assert.ThrowsAny <ServiceValidationException>(() => validateService.Validate(vm)); vm.Date = DateTimeOffset.UtcNow.AddHours(2); validateService = new ValidateService(serviceProvider); Assert.ThrowsAny <ServiceValidationException>(() => validateService.Validate(vm)); vm.Id = 1; validateService = new ValidateService(serviceProvider); Assert.ThrowsAny <ServiceValidationException>(() => validateService.Validate(vm)); vm.Id = 0; vm.AvalTransformationProductionOrders.Add(new InputAvalTransformationProductionOrderViewModel() { IsSave = false }); validateService = new ValidateService(serviceProvider); Assert.ThrowsAny <ServiceValidationException>(() => validateService.Validate(vm)); vm.AvalTransformationProductionOrders.Add(new InputAvalTransformationProductionOrderViewModel() { IsSave = true }); validateService = new ValidateService(serviceProvider); Assert.ThrowsAny <ServiceValidationException>(() => validateService.Validate(vm)); vm.Id = 1; validateService = new ValidateService(serviceProvider); Assert.ThrowsAny <ServiceValidationException>(() => validateService.Validate(vm)); }
public void Validate_Success() { Mock <IServiceProvider> serviceProvider = new Mock <IServiceProvider>(); ColorReceiptItemViewModel viewModel = new ColorReceiptItemViewModel(); ValidateService service = new ValidateService(serviceProvider.Object); service.Validate(viewModel); }
public void Validate_Throws_ServiceValidationExeption() { Mock <IServiceProvider> serviceProvider = new Mock <IServiceProvider>(); BuyerBrandViewModel viewModel = new BuyerBrandViewModel(); ValidateService service = new ValidateService(serviceProvider.Object); Assert.Throws <ServiceValidationException>(() => service.Validate(viewModel)); }
public void Validate_Throws_ServiceValidationExeption() { Mock <IServiceProvider> serviceProvider = new Mock <IServiceProvider>(); StockTransferNoteViewModel viewModel = new StockTransferNoteViewModel(); ValidateService service = new ValidateService(serviceProvider.Object); Assert.Throws <ServiceValidationExeption>(() => service.Validate(viewModel)); }
public virtual void ValidateVM() { var dbContext = DbContext(GetCurrentMethod()); var serviceProvider = GetServiceProviderMock(dbContext).Object; DOAvalFacade facade = new DOAvalFacade(serviceProvider, dbContext); var data = new DOAvalViewModel(); var validateService = new ValidateService(serviceProvider); Assert.ThrowsAny <ServiceValidationException>(() => validateService.Validate(data)); data.DOAvalItems = new List <DOAvalItemViewModel>() { new DOAvalItemViewModel() }; Assert.ThrowsAny <ServiceValidationException>(() => validateService.Validate(data)); }
public async Task <IActionResult> Patch([FromRoute] int id, [FromBody] JsonPatchDocument <GarmentPreSalesContract> patch) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { var model = await Facade.ReadByIdAsync(id); if (model == null) { Dictionary <string, object> Result = new ResultFormatter(ApiVersion, Common.NOT_FOUND_STATUS_CODE, Common.NOT_FOUND_MESSAGE) .Fail(); return(NotFound(Result)); } else { patch.ApplyTo(model); var viewModel = Mapper.Map <GarmentPreSalesContractViewModel>(model); ValidateService.Validate(viewModel); IdentityService.Username = User.Claims.ToArray().SingleOrDefault(p => p.Type.Equals("username")).Value; IdentityService.Token = Request.Headers["Authorization"].FirstOrDefault().Replace("Bearer ", ""); if (id != viewModel.Id) { Dictionary <string, object> Result = new ResultFormatter(ApiVersion, Common.BAD_REQUEST_STATUS_CODE, Common.BAD_REQUEST_MESSAGE) .Fail(); return(BadRequest(Result)); } await Facade.UpdateAsync(id, model); return(NoContent()); } } catch (ServiceValidationException e) { Dictionary <string, object> Result = new ResultFormatter(ApiVersion, Common.BAD_REQUEST_STATUS_CODE, Common.BAD_REQUEST_MESSAGE) .Fail(e); return(BadRequest(Result)); } catch (Exception e) { Dictionary <string, object> Result = new ResultFormatter(ApiVersion, Common.INTERNAL_ERROR_STATUS_CODE, e.Message) .Fail(); return(StatusCode(Common.INTERNAL_ERROR_STATUS_CODE, Result)); } }
public async Task <ActionResult> Create([FromBody] KanbanCreateViewModel viewModel) { try { VerifyUser(); ValidateService.Validate(viewModel); foreach (var cart in viewModel.Carts) { KanbanViewModel vmToCreate = new KanbanViewModel { Cart = cart, CurrentQty = viewModel.CurrentQty ?? 0, CurrentStepIndex = viewModel.CurrentStepIndex ?? 0, GoodOutput = viewModel.GoodOutput ?? 0, Grade = viewModel.Grade, Instruction = viewModel.Instruction, OldKanbanId = viewModel.OldKanbanId, ProductionOrder = viewModel.ProductionOrder, IsBadOutput = viewModel.IsBadOutput, BadOutput = viewModel.BadOutput ?? 0, IsReprocess = viewModel.IsReprocess, SelectedProductionOrderDetail = viewModel.SelectedProductionOrderDetail }; if (cart.reprocess == REPROSES || cart.reprocess == LANJUT_PROSES) { vmToCreate.IsReprocess = cart.IsReprocess; vmToCreate.Instruction = cart.Instruction; } KanbanModel model = Mapper.Map <KanbanModel>(vmToCreate); await Facade.CreateAsync(model); } Dictionary <string, object> Result = new ResultFormatter(ApiVersion, General.CREATED_STATUS_CODE, General.OK_MESSAGE) .Ok(); return(Created(String.Concat(Request.Path, "/", 0), Result)); } catch (ServiceValidationException e) { Dictionary <string, object> Result = new ResultFormatter(ApiVersion, General.BAD_REQUEST_STATUS_CODE, General.BAD_REQUEST_MESSAGE) .Fail(e); return(BadRequest(Result)); } catch (Exception e) { Dictionary <string, object> Result = new ResultFormatter(ApiVersion, General.INTERNAL_ERROR_STATUS_CODE, e.Message) .Fail(); return(StatusCode(General.INTERNAL_ERROR_STATUS_CODE, Result)); } }
public void Test_Validate_Should_Return_Null_When_Empty_Class() { // Arrange var ValidateService = new ValidateService(); var testClass = new TestEmptyClass(); // Act var errors = ValidateService.Validate(testClass); // Assert Assert.IsNull(errors); }
public void Test_Validate_Should_Return_ValidationError_With_Property_Name_As_Key() { // Arrange var ValidateService = new ValidateService(); var testClass = new TestClassWithAttrWithoutKey(); // Act var errors = ValidateService.Validate(testClass); // Assert Assert.AreEqual("TestProperty", errors.Errors[0].Key); }
public void Test_Validate_Should_Return_Null_Object_When_T_Is_Base_Type() { // Arrange var ValidateService = new ValidateService(); var testClass = new TestDerivedClass(); // Act var errors = ValidateService.Validate <TestBaseClass>(testClass); // Assert Assert.IsNull(errors); }
public void Test_Validate_Should_Return_Null_When_Class_With_Invalid_Method() { // Arrange var ValidateService = new ValidateService(); var testClass = new TestClassWithInvalidMethod(); // Act var errors = ValidateService.Validate(testClass); // Assert Assert.IsNull(errors); }
public void Test_Validate_Should_Return_Null_When_Class_With_Another_Attributes() { // Arrange var ValidateService = new ValidateService(); var testClass = new TestClassWithAnotherAttr(); // Act var errors = ValidateService.Validate(testClass); // Assert Assert.IsNull(errors); }
public void Validate_Success() { Mock <IServiceProvider> serviceProvider = new Mock <IServiceProvider>(); BudgetExportGarmentReportViewModel viewModel = new BudgetExportGarmentReportViewModel() { count = 1, Article = "Article" }; ValidateService service = new ValidateService(serviceProvider.Object); service.Validate(viewModel); }
public void Test_Validate_Should_Return_Only_One_ValidationError_When_Two_Similar_Errors_Are_Triggered() { // Arrange var ValidateService = new ValidateService(); var testClass = new TestClassWithSimilarValidationErrors(); // Act var errors = ValidateService.Validate(testClass); // Assert Assert.AreEqual(1, errors.Errors.Length); Assert.AreEqual("similarError", errors.Errors[0].Key); }
public virtual void ValidateVM() { var dbContext = DbContext(GetCurrentMethod()); var serviceProvider = GetServiceProviderMock(dbContext).Object; DailyMonitoringEventFacade facade = new DailyMonitoringEventFacade(serviceProvider, dbContext); var data = new DailyMonitoringEventViewModel(); var validateService = new ValidateService(serviceProvider); Assert.ThrowsAny <ServiceValidationException>(() => validateService.Validate(data)); data.DailyMonitoringEventLossEventItems = new List <DailyMonitoringEventLossEventItemViewModel>() { new DailyMonitoringEventLossEventItemViewModel() }; data.DailyMonitoringEventProductionOrderItems = new List <DailyMonitoringEventProductionOrderItemViewModel>() { new DailyMonitoringEventProductionOrderItemViewModel() }; Assert.ThrowsAny <ServiceValidationException>(() => validateService.Validate(data)); }
public async Task <IActionResult> Post([FromBody] UnitReceiptNoteViewModel vm) { identityService.Token = Request.Headers["Authorization"].First().Replace("Bearer ", ""); identityService.Username = User.Claims.Single(p => p.Type.Equals("username")).Value; if (vm.supplier != null) { if (vm.no == "" || vm.no == null) { if (vm.supplier.import == true) { vm.no = "BPI"; } else { vm.no = "BPL"; } } } UnitReceiptNote m = _mapper.Map <UnitReceiptNote>(vm); ValidateService validateService = (ValidateService)_facade.serviceProvider.GetService(typeof(ValidateService)); try { validateService.Validate(vm); int result = await _facade.Create(m, identityService.Username); Dictionary <string, object> Result = new ResultFormatter(ApiVersion, General.CREATED_STATUS_CODE, General.OK_MESSAGE) .Ok(); return(Created(String.Concat(Request.Path, "/", 0), Result)); } catch (ServiceValidationExeption e) { Dictionary <string, object> Result = new ResultFormatter(ApiVersion, General.BAD_REQUEST_STATUS_CODE, General.BAD_REQUEST_MESSAGE) .Fail(e); return(BadRequest(Result)); } catch (Exception e) { Dictionary <string, object> Result = new ResultFormatter(ApiVersion, General.INTERNAL_ERROR_STATUS_CODE, e.Message) .Fail(); return(StatusCode(General.INTERNAL_ERROR_STATUS_CODE, Result)); } }
public void Should_Success_Instantiate() { //Setup Mock <IServiceProvider> serviceProviderMock = new Mock <IServiceProvider>(); ValidateService service = new ValidateService(serviceProviderMock.Object); UnitViewModel stage = new UnitViewModel() { Code = "Code", Division = new DivisionViewModel() { Name = "Name" }, Name = "Name" }; //Act service.Validate(stage); }
public void Validate_AgentNoUse_ReturnForbidden(int useState, HttpStatusCode expectedCode) { //配置 IGetAgentInfoService getAgentInfoService = Substitute.For <IGetAgentInfoService>(); ICheckGetSecCode checkGetSecCode = Substitute.For <ICheckGetSecCode>(); getAgentInfoService.GetAgentModelFactory(Arg.Any <int>()).Returns(new bx_agent() { IsUsed = useState }); ValidateService validateService = new ValidateService(getAgentInfoService, checkGetSecCode); //操作 var result = validateService.Validate(new BaseRequest() { Agent = 1 }, null); //断言 Assert.AreEqual(expectedCode, result.Status); }
public void Validate_AgentCanUse_NextCalled() { //配置 IGetAgentInfoService getAgentInfoService = Substitute.For <IGetAgentInfoService>(); ICheckGetSecCode checkGetSecCode = Substitute.For <ICheckGetSecCode>(); getAgentInfoService.GetAgentModelFactory(Arg.Any <int>()).Returns(new bx_agent() { IsUsed = 1 }); ValidateService validateService = new ValidateService(getAgentInfoService, checkGetSecCode); //操作 var result = validateService.Validate(new BaseRequest() { Agent = 1 }, null); //断言 checkGetSecCode.Received().ValidateReqest(null, Arg.Any <string>(), Arg.Any <string>()); }
public override async Task <ActionResult> Post([FromBody] ColorReceiptViewModel viewModel) { try { VerifyUser(); ValidateService.Validate(viewModel); if (viewModel.ChangeTechnician) { var technician = await Facade.CreateTechnician(viewModel.NewTechnician); viewModel.Technician = new TechnicianViewModel() { Id = technician.Id, Name = technician.Name }; } ColorReceiptModel model = Mapper.Map <ColorReceiptModel>(viewModel); await Facade.CreateAsync(model); Dictionary <string, object> Result = new ResultFormatter(ApiVersion, General.CREATED_STATUS_CODE, General.OK_MESSAGE) .Ok(); return(Created(String.Concat(Request.Path, "/", 0), Result)); } catch (ServiceValidationException e) { Dictionary <string, object> Result = new ResultFormatter(ApiVersion, General.BAD_REQUEST_STATUS_CODE, General.BAD_REQUEST_MESSAGE) .Fail(e); return(BadRequest(Result)); } catch (Exception e) { Dictionary <string, object> Result = new ResultFormatter(ApiVersion, General.INTERNAL_ERROR_STATUS_CODE, e.Message) .Fail(); return(StatusCode(General.INTERNAL_ERROR_STATUS_CODE, Result)); } }
public void Validate_SecCodeNoPass_ReturnFalse(bool useState, HttpStatusCode expectedCode) { //配置 IGetAgentInfoService getAgentInfoService = Substitute.For <IGetAgentInfoService>(); ICheckGetSecCode checkGetSecCode = Substitute.For <ICheckGetSecCode>(); getAgentInfoService.GetAgentModelFactory(Arg.Any <int>()).Returns(new bx_agent() { IsUsed = 1 }); checkGetSecCode.ValidateReqest(null, Arg.Any <string>(), Arg.Any <string>()).Returns(useState); ValidateService validateService = new ValidateService(getAgentInfoService, checkGetSecCode); //操作 var result = validateService.Validate(new BaseRequest() { Agent = 1 }, null); //断言 Assert.AreEqual(expectedCode, result.Status); }
public override async Task <ActionResult> Post([FromBody] DailyBankTransactionViewModel viewModel) { try { VerifyUser(); ValidateService.Validate(viewModel); DailyBankTransactionModel model = Mapper.Map <DailyBankTransactionModel>(viewModel); if (viewModel.Status.Equals("OUT", StringComparison.OrdinalIgnoreCase) && viewModel.SourceType.Equals("pendanaan", StringComparison.OrdinalIgnoreCase)) { await Service.CreateInOutTransactionAsync(model); } else { await Service.CreateAsync(model); } Dictionary <string, object> Result = new ResultFormatter(ApiVersion, Utilities.General.CREATED_STATUS_CODE, Utilities.General.OK_MESSAGE) .Ok(); return(Created(String.Concat(Request.Path, "/", 0), Result)); } catch (ServiceValidationException e) { Dictionary <string, object> Result = new ResultFormatter(ApiVersion, Utilities.General.BAD_REQUEST_STATUS_CODE, Utilities.General.BAD_REQUEST_MESSAGE) .Fail(e); return(BadRequest(Result)); } catch (Exception e) { Dictionary <string, object> Result = new ResultFormatter(ApiVersion, Utilities.General.INTERNAL_ERROR_STATUS_CODE, e.Message) .Fail(); return(StatusCode(Utilities.General.INTERNAL_ERROR_STATUS_CODE, Result)); } }
public override async Task <IActionResult> Put([FromRoute] int id, [FromBody] COAViewModel viewModel) { try { VerifyUser(); ValidateService.Validate(viewModel); if (id != viewModel.Id) { Dictionary <string, object> Result = new ResultFormatter(ApiVersion, General.BAD_REQUEST_STATUS_CODE, General.BAD_REQUEST_MESSAGE) .Fail(); return(BadRequest(Result)); } COAModel model = Mapper.Map <COAModel>(viewModel); Transfrom(model); await Service.UpdateAsync(id, model); return(NoContent()); } catch (ServiceValidationException e) { Dictionary <string, object> Result = new ResultFormatter(ApiVersion, General.BAD_REQUEST_STATUS_CODE, General.BAD_REQUEST_MESSAGE) .Fail(e); return(BadRequest(Result)); } catch (Exception e) { Dictionary <string, object> Result = new ResultFormatter(ApiVersion, General.INTERNAL_ERROR_STATUS_CODE, e.Message) .Fail(); return(StatusCode(General.INTERNAL_ERROR_STATUS_CODE, Result)); } }