public async Task <IActionResult> Post([FromBody] GarmentAmendLetterOfCreditViewModel viewModel)
        {
            try
            {
                VerifyUser();
                _validateService.Validate(viewModel);
                var result = await _service.Create(viewModel);

                return(Created("/", result));
            }
            catch (ServiceValidationException ex)
            {
                var Result = new
                {
                    error      = ResultFormatter.Fail(ex),
                    apiVersion = "1.0.0",
                    statusCode = HttpStatusCode.BadRequest,
                    message    = "Data does not pass validation"
                };

                return(new BadRequestObjectResult(Result));
            }
            catch (Exception ex)
            {
                return(StatusCode((int)HttpStatusCode.InternalServerError, ex.Message));
            }
        }
        public IActionResult Post([FromBody] FabricSKUFormDto form)
        {
            try
            {
                VerifyUser();
                _validateService.Validate(form);
                var result = _service.CreateSKU(form);

                return(Created(HttpContext.Request.Path, result));
            }
            catch (ServiceValidationException ex)
            {
                var Result = new
                {
                    error      = ResultFormatter.Fail(ex),
                    apiVersion = "1.0.0",
                    statusCode = HttpStatusCode.BadRequest,
                    message    = "Data does not pass validation"
                };

                return(new BadRequestObjectResult(Result));
            }
            catch (Exception ex)
            {
                return(StatusCode((int)HttpStatusCode.InternalServerError, ex.Message));
            }
        }
        public async Task <ActionResult> Post([FromBody] PaymentDispositionNoteViewModel viewModel)
        {
            try
            {
                VerifyUser();

                ValidateService.Validate(viewModel);
                viewModel.BankAccountCOA = viewModel.AccountBank.AccountCOA;
                PaymentDispositionNoteModel model = Mapper.Map <PaymentDispositionNoteModel>(viewModel);
                model.FixFailAutoMapper(viewModel.AccountBank.BankCode);
                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));
            }
        }
Example #4
0
        public virtual async Task <ActionResult> Post([FromBody] TViewModel viewModel)
        {
            try
            {
                VerifyUser();
                ValidateService.Validate(viewModel);

                TModel model = Mapper.Map <TModel>(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 async Task <IActionResult> Post([FromBody] OthersExpenditureProofDocumentCreateUpdateViewModel viewModel)
        {
            try
            {
                VerifyUser();

                _validateService.Validate(viewModel);

                await _service.CreateAsync(viewModel);

                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));
            }
        }
Example #6
0
        public async Task <IActionResult> Post([FromBody] CostCalculationViewModel viewModel)
        {
            try
            {
                VerifyUser();

                _validateService.Validate(viewModel);
                var createModel = viewModel.MapViewModelToCreateModel();
                var result      = await _service.InsertSingle(createModel);

                return(Created($"{Request.Path}/{result}", new
                {
                    apiVersion = API_VERSION,
                    statusCode = (int)HttpStatusCode.Created,
                    message = "Data Created Successfully!"
                }));
            }
            catch (ServiceValidationException e)
            {
                var validationResult = new ResultFormatter(API_VERSION, (int)HttpStatusCode.BadRequest, "Data Does Not Pass Validation!").Fail(e);
                return(BadRequest(validationResult));
            }
            catch (Exception e)
            {
                var errorResult = new ResultFormatter(API_VERSION, (int)HttpStatusCode.InternalServerError, e.Message + "\n" + e.StackTrace).Fail();
                return(StatusCode((int)HttpStatusCode.InternalServerError, errorResult));
            }
        }
        public async Task <ActionResult> Post([FromBody] VbNonPORequestViewModel viewModel)
        {
            try
            {
                VerifyUser();
                _validateService.Validate(viewModel);

                var model = _mapper.Map <VbRequestModel>(viewModel);

                await _service.CreateAsync(model, viewModel);

                await _service.MappingData(viewModel);

                var result = new ResultFormatter(ApiVersion, General.CREATED_STATUS_CODE, General.OK_MESSAGE).Ok();

                return(Created(String.Concat(Request.Path, "/", 0), result));
            }
            catch (ServiceValidationException e)
            {
                var result = new ResultFormatter(ApiVersion, General.BAD_REQUEST_STATUS_CODE, General.BAD_REQUEST_MESSAGE).Fail(e);
                return(BadRequest(result));
            }
            catch (Exception e)
            {
                var result =
                    new ResultFormatter(ApiVersion, General.INTERNAL_ERROR_STATUS_CODE, e.Message)
                    .Fail();
                return(StatusCode(General.INTERNAL_ERROR_STATUS_CODE, result));
            }
        }
        public async Task <IActionResult> Post([FromBody] VBRealizationIdListDto viewModel)
        {
            try
            {
                VerifyUser();
                _validateService.Validate(viewModel);

                await _service.SubmitToVerification(viewModel.VBRealizationIds);

                Dictionary <string, object> Result =
                    new ResultFormatter(ApiVersion, General.CREATED_STATUS_CODE, General.OK_MESSAGE)
                    .Ok();
                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));
            }
        }
        public async Task <ActionResult> Post([FromBody] List <PurchasingDispositionExpeditionViewModel> viewModel)
        {
            try
            {
                VerifyUser();
                ValidateService.Validate(viewModel);
                foreach (var vm in viewModel)
                {
                    ValidateService.Validate(viewModel);
                    PurchasingDispositionExpeditionModel model = Mapper.Map <PurchasingDispositionExpeditionModel>(vm);
                    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));
            }
        }
Example #10
0
        public async Task <IActionResult> Post([FromBody] OutputTransitViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                var excpetion = new
                {
                    error = ResultFormatter.FormatErrorMessage(ModelState)
                };
                return(new BadRequestObjectResult(excpetion));
            }
            try
            {
                VerifyUser();
                ValidateService.Validate(viewModel);
                var result = await _service.Create(viewModel);

                return(Created("/", result));
            }
            catch (ServiceValidationException ex)
            {
                var Result = new
                {
                    error      = ResultFormatter.Fail(ex),
                    apiVersion = "1.0.0",
                    statusCode = HttpStatusCode.BadRequest,
                    message    = "Data does not pass validation"
                };

                return(new BadRequestObjectResult(Result));
            }
            catch (Exception ex)
            {
                return(StatusCode((int)HttpStatusCode.InternalServerError, ex.Message));
            }
        }
        public async Task <ActionResult> Post([FromBody] Absensi Absensi)
        {
            try
            {
                VerifyUser();
                _validateService.Validate(Absensi);

                await _AbsensiService.Create(Absensi);

                return(CreatedAtRoute(
                           "Get",
                           new { Id = Absensi.Id },
                           Absensi));
                //var result = new ResultFormatter(API_VERSION, General.CREATED_STATUS_CODE, General.OK_MESSAGE)
                //  .Ok();
                //return Created(string.Concat(Request.Path, "/", 0), result);
            }
            catch (ServiceValidationExeption e)
            {
                var result = new ResultFormatter(API_VERSION, General.BAD_REQUEST_STATUS_CODE, General.BAD_REQUEST_MESSAGE)
                             .Fail(e);
                return(BadRequest(result));
            }
            catch (Exception e)
            {
                var result = new ResultFormatter(API_VERSION, General.INTERNAL_ERROR_STATUS_CODE, e.Message)
                             .Fail();
                return(StatusCode(General.INTERNAL_ERROR_STATUS_CODE, result));
            }
        }
        public async Task <IActionResult> Post([FromBody] InventoryWeavingDocumentOutViewModel viewModel)
        {
            try
            {
                VerifyUser();
                ValidateService.Validate(viewModel);

                InventoryWeavingDocument model = await Service.MapToModel(viewModel);


                await Service.Create(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 (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));
            }
        }
Example #13
0
        public async Task <IActionResult> SendToVerification([FromBody] SendToVerificationAccountingForm form)
        {
            try
            {
                VerifyUser();
                _validateService.Validate(form);

                var id = await _service.SendToVerification(form);


                var result = new ResultFormatter(ApiVersion, General.CREATED_STATUS_CODE, General.OK_MESSAGE).Ok();

                return(Created(string.Concat(Request.Path, "/", id), result));
            }
            catch (ServiceValidationException e)
            {
                var result = new ResultFormatter(ApiVersion, General.BAD_REQUEST_STATUS_CODE, General.BAD_REQUEST_MESSAGE).Fail(e);
                return(BadRequest(result));
            }
            catch (Exception e)
            {
                var 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(Medical medical, IFormFile stream)
        {
            try
            {
                VerifyUser();
                _validateService.Validate(medical);

                //upload file
                if (CloudStorageAccount.TryParse(config.Value.StorageConnection, out CloudStorageAccount storageAccount))
                {
                    CloudBlobClient    blobClient = storageAccount.CreateCloudBlobClient();
                    CloudBlobContainer container  = blobClient.GetContainerReference(config.Value.Container);

                    var chars       = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
                    var stringChars = new char[8];
                    var random      = new Random();
                    for (int i = 0; i < stringChars.Length; i++)
                    {
                        stringChars[i] = chars[random.Next(chars.Length)];
                    }

                    var            finalString = new String(stringChars);
                    CloudBlockBlob blockBlob   = container.GetBlockBlobReference(finalString + stream.FileName);

                    string fileUrl = blockBlob?.Uri.ToString();
                    medical.FileUrl = fileUrl.ToString();

                    await blockBlob.UploadFromStreamAsync(stream.OpenReadStream());
                }
                else
                {
                    return(null);
                }


                await _medicalService.Create(medical);

                return(CreatedAtRoute("Get", new { Id = medical.Id }, medical));
            }


            catch (ServiceValidationExeption e)
            {
                var result = new ResultFormatter(API_VERSION, General.BAD_REQUEST_STATUS_CODE, General.BAD_REQUEST_MESSAGE)
                             .Fail(e);
                return(BadRequest(result));
            }
            catch (Exception e)
            {
                var result = new ResultFormatter(API_VERSION, General.INTERNAL_ERROR_STATUS_CODE, e.Message)
                             .Fail();
                return(StatusCode(General.INTERNAL_ERROR_STATUS_CODE, result));
            }
        }
 public async Task <ActionResult> Post([FromBody] Activity activity)
 {
     try
     {
         VerifyUser();
         _validateService.Validate(activity);
         var query = _activity.Create(activity);
         return(Ok(query));
     }catch (Exception e)
     {
         var result = new ResultFormatter(API_VERSION, General.INTERNAL_ERROR_STATUS_CODE, e.Message).Fail();
         return(StatusCode(General.INTERNAL_ERROR_STATUS_CODE, result));
     }
 }
        public async Task <ActionResult> Post([FromBody] PurchasingDispositionAcceptanceViewModel viewModel)
        {
            try
            {
                VerifyUser();
                ValidateService.Validate(viewModel);

                await Service.PurchasingDispositionAcceptance(viewModel);

                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 (AggregateException ex)
            {
                string message = string.Join(',', ex.InnerExceptions.Select(x => x.Message));
                Dictionary <string, object> Result =
                    new ResultFormatter(ApiVersion, General.INTERNAL_ERROR_STATUS_CODE, message)
                    .Fail();
                return(StatusCode(General.INTERNAL_ERROR_STATUS_CODE, 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));
            }
        }
Example #17
0
        public async Task <IActionResult> Put([FromRoute] int id, [FromBody] BankExpenditureNoteViewModel vm)
        {
            identityService.Username = User.Claims.Single(p => p.Type.Equals("username")).Value;

            BankExpenditureNoteModel m = mapper.Map <BankExpenditureNoteModel>(vm);

            IValidateService validateService = (IValidateService)serviceProvider.GetService(typeof(IValidateService));

            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));
            }
        }
Example #18
0
        public void PostSubmitInfo_MessageCenterIsNull_ReturnOK()
        {
            //配置
            IValidateService validateService = Substitute.For <IValidateService>();
            IMessageCenter   messageCenter   = Substitute.For <IMessageCenter>();
            IRemoveHeBaoKey  removeHeBaoKey  = Substitute.For <IRemoveHeBaoKey>();
            IPostValidate    postValidate    = Substitute.For <IPostValidate>();

            validateService.Validate(Arg.Any <PostSubmitInfoRequest>(), Arg.Any <IEnumerable <KeyValuePair <string, string> > >()).Returns(new BaseResponse()
            {
                Status = HttpStatusCode.OK
            });
            postValidate.SubmitInfoValidate(Arg.Any <PostSubmitInfoRequest>()).Returns(Tuple.Create <BaseResponse, bx_userinfo, bx_submit_info>(new BaseResponse()
            {
                Status = HttpStatusCode.OK
            }, new bx_userinfo(), new bx_submit_info()));
            removeHeBaoKey.RemoveHeBao(Arg.Any <PostSubmitInfoRequest>()).Returns(x => "test-string");
            messageCenter.SendToMessageCenter(Arg.Any <string>(), Arg.Any <string>()).Returns(x => null);
            PostSubmitInfoService postSubmitInfoService = new PostSubmitInfoService(validateService, messageCenter, removeHeBaoKey, postValidate);
            //操作
            var result = postSubmitInfoService.PostSubmitInfo(new PostSubmitInfoRequest()
            {
                Source = 1
            }, null);

            //断言
            Assert.AreEqual(HttpStatusCode.OK, result.Status);
        }
Example #19
0
        public async Task <IActionResult> Post([FromBody] GarmentPOMasterDistributionViewModel viewModel)
        {
            try
            {
                identityService.Username       = User.Claims.Single(p => p.Type.Equals("username")).Value;
                identityService.TimezoneOffset = int.Parse(Request.Headers["x-timezone-offset"].First());

                IValidateService validateService = (IValidateService)serviceProvider.GetService(typeof(IValidateService));

                validateService.Validate(viewModel);

                var model = mapper.Map <GarmentPOMasterDistribution>(viewModel);

                await facade.Create(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 (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] UnitReceiptNoteViewModel vm)
        {
            identityService.Token    = Request.Headers["Authorization"].First().Replace("Bearer ", "");
            identityService.Username = User.Claims.Single(p => p.Type.Equals("username")).Value;

            UnitReceiptNote m = _mapper.Map <UnitReceiptNote>(vm);

            IValidateService validateService = (IValidateService)_serviceProvider.GetService(typeof(IValidateService));

            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 IActionResult DownloadFile(DateTimeOffset?date, string unit, string storage, string storageName)
        {
            try
            {
                VerifyUser();

                var downloadFile = new GarmentStockOpnameDownload(date, unit, storage, storageName);
                _validateService.Validate(downloadFile);

                var stream = _facade.Download(date.Value, unit, storage, storageName);
                stream.Position = 0;

                FileStreamResult fileStreamResult = new FileStreamResult(stream, "application/excel");
                fileStreamResult.FileDownloadName = $"Garment Stock Opname {unit} {storageName} {date.Value.ToOffset(new TimeSpan(_identityService.TimezoneOffset, 0, 0)).ToString("dd MMMM yyyy")}.xlsx";

                return(fileStreamResult);
            }
            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(e.Message);
                return(StatusCode(General.INTERNAL_ERROR_STATUS_CODE, Result));
            }
        }
Example #22
0
        public async Task <IActionResult> Put(int id, [FromBody] GarmentExternalPurchaseOrderViewModel ViewModel)
        {
            try
            {
                identityService.Username = User.Claims.Single(p => p.Type.Equals("username")).Value;

                IValidateService validateService = (IValidateService)serviceProvider.GetService(typeof(IValidateService));

                validateService.Validate(ViewModel);

                var model = mapper.Map <GarmentExternalPurchaseOrder>(ViewModel);

                await facade.Update(id, 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 async Task <IActionResult> Put(int id, [FromBody] GarmentUnitExpenditureNoteViewModel ViewModel)
        {
            try
            {
                identityService.Username = User.Claims.Single(p => p.Type.Equals("username")).Value;

                identityService.TimezoneOffset = int.Parse(Request.Headers["x-timezone-offset"].First());

                IValidateService validateService = (IValidateService)serviceProvider.GetService(typeof(IValidateService));

                validateService.Validate(ViewModel);

                var model = mapper.Map <GarmentUnitExpenditureNote>(ViewModel);

                await facade.Update(id, model);

                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));
            }
        }
Example #24
0
        public void PostSubmitInfo_HeBaoKeyIsException_ReturnExpectationFailed()
        {
            //配置
            IValidateService validateService = Substitute.For <IValidateService>();
            IMessageCenter   messageCenter   = Substitute.For <IMessageCenter>();
            IRemoveHeBaoKey  removeHeBaoKey  = Substitute.For <IRemoveHeBaoKey>();
            IPostValidate    postValidate    = Substitute.For <IPostValidate>();

            validateService.Validate(Arg.Any <PostSubmitInfoRequest>(), Arg.Any <IEnumerable <KeyValuePair <string, string> > >()).Returns(new BaseResponse()
            {
                Status = HttpStatusCode.OK
            });
            postValidate.SubmitInfoValidate(Arg.Any <PostSubmitInfoRequest>()).Returns(Tuple.Create <BaseResponse, bx_userinfo, bx_submit_info>(new BaseResponse()
            {
                Status = HttpStatusCode.OK
            }, new bx_userinfo(), new bx_submit_info()));
            removeHeBaoKey.When(x => x.RemoveHeBao(Arg.Any <PostSubmitInfoRequest>())).Do(info =>
            {
                throw new RedisOperateException();
            });
            PostSubmitInfoService postSubmitInfoService = new PostSubmitInfoService(validateService, messageCenter, removeHeBaoKey, postValidate);
            //操作
            var result = postSubmitInfoService.PostSubmitInfo(new PostSubmitInfoRequest()
            {
                Source = 1, LicenseNo = "京", Agent = 102, CustKey = "aaaaa", RenewalCarType = 0
            }, null);

            //断言
            Assert.AreEqual(HttpStatusCode.ExpectationFailed, result.Status);
        }
Example #25
0
        public async Task <IActionResult> Post([FromBody] GarmentInvoiceViewModel ViewModel)
        {
            try
            {
                identityService.Username = User.Claims.Single(p => p.Type.Equals("username")).Value;
                identityService.Token    = Request.Headers["Authorization"].FirstOrDefault().Replace("Bearer ", "");

                IValidateService validateService = (IValidateService)serviceProvider.GetService(typeof(IValidateService));

                validateService.Validate(ViewModel);

                var model = mapper.Map <GarmentInvoice>(ViewModel);

                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));
            }
        }
Example #26
0
        public async Task <IActionResult> Put([FromRoute] int id, [FromBody] GarmentPackingListUnitPackingViewModel viewModel)
        {
            try
            {
                VerifyUser();
                _validateService.Validate(viewModel);
                var result = await _service.Update(id, viewModel);

                return(Ok(result));
            }
            catch (ServiceValidationException ex)
            {
                var Result = new
                {
                    error      = ResultFormatter.Fail(ex),
                    apiVersion = "1.0.0",
                    statusCode = HttpStatusCode.BadRequest,
                    message    = "Data does not pass validation"
                };

                return(new BadRequestObjectResult(Result));
            }
            catch (Exception ex)
            {
                return(StatusCode((int)HttpStatusCode.InternalServerError, ex.Message));
            }
        }
        public async Task <IActionResult> UnitPaymentOrderPut([FromBody] CreditorAccountUnitPaymentOrderPostedViewModel viewModel)
        {
            try
            {
                VerifyUser();
                ValidateService.Validate(viewModel.CreditorAccounts);

                await Service.UpdateFromUnitPaymentOrderAsync(viewModel);

                return(NoContent());
            }
            catch (NotFoundException)
            {
                Dictionary <string, object> Result =
                    new ResultFormatter(ApiVersion, General.BAD_REQUEST_STATUS_CODE, General.BAD_REQUEST_MESSAGE)
                    .Fail();
                return(BadRequest(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));
            }
        }
Example #28
0
 public override void Create(IEntity partner)
 {
     if (_validateService.Validate(partner))
     {
         base.Create(partner);
     }
     else
     {
         Console.WriteLine("Doğrulama başarısız.");
     }
 }
 public void Add(Customer customer)
 {
     if (_validateServices.Validate(customer) == true)
     {
         Console.WriteLine(customer.FirstName + " " + customer.LastName + " Doğrulamadan Geçti.\nKayıt Olundu");
         _loggerServices.Add(customer);
     }
     else
     {
         Console.WriteLine(customer.FirstName + " " + customer.LastName + " Doğrulamdan Geçemedi.\nKayıt Olunamadı.");
     }
 }
Example #30
0
        public IActionResult PostCashflowUnit([FromBody] CashflowUnitFormDto form)
        {
            try
            {
                VerifyUser();
                _validateService.Validate(form);

                var id = _service.CreateBudgetCashflowUnit(form);

                var result = new ResultFormatter(ApiVersion, General.CREATED_STATUS_CODE, General.OK_MESSAGE).Ok();

                return(Created(string.Concat(Request.Path, "/", id), result));
            }
            catch (ServiceValidationException e)
            {
                var result = new ResultFormatter(ApiVersion, General.BAD_REQUEST_STATUS_CODE, General.BAD_REQUEST_MESSAGE).Fail(e);
                return(BadRequest(result));
            }
            catch (Exception e)
            {
                var result =
                    new ResultFormatter(ApiVersion, General.INTERNAL_ERROR_STATUS_CODE, e.Message)
                    .Fail();
                return(StatusCode(General.INTERNAL_ERROR_STATUS_CODE, result));
            }
        }