Exemplo n.º 1
0
        public async Task <IActionResult> Put([FromRoute] int id, [FromBody] BankExpenditureNoteViewModel vm)
        {
            identityService.Username = User.Claims.Single(p => p.Type.Equals("username")).Value;
            identityService.Token    = Request.Headers["Authorization"].FirstOrDefault().Replace("Bearer ", "");

            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);

                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));
            }
        }
Exemplo n.º 2
0
        public void Should_Success_Validate_Data_Date_Greater_Than_Now()
        {
            BankExpenditureNoteViewModel vm = new BankExpenditureNoteViewModel()
            {
                Date    = DateTime.Now.AddDays(2),
                Bank    = null,
                Details = null
            };

            Assert.True(vm.Validate(null).Count() > 0);
        }
Exemplo n.º 3
0
        public void Should_Success_Validate_Data()
        {
            BankExpenditureNoteViewModel vm = new BankExpenditureNoteViewModel()
            {
                Date    = null,
                Bank    = null,
                Details = new List <BankExpenditureNoteDetailViewModel>()
            };

            Assert.True(vm.Validate(null).Count() > 0);
        }
        public async Task <IActionResult> GetById([FromRoute] int Id)
        {
            try
            {
                var indexAcceptPdf = Request.Headers["Accept"].ToList().IndexOf("application/pdf");
                var model          = await facade.ReadById(Id);

                BankExpenditureNoteViewModel viewModel = mapper.Map <BankExpenditureNoteViewModel>(model);

                if (model == null)
                {
                    Dictionary <string, object> Result =
                        new ResultFormatter(ApiVersion, General.NOT_FOUND_STATUS_CODE, General.NOT_FOUND_MESSAGE)
                        .Fail();
                    return(NotFound(Result));
                }

                if (indexAcceptPdf < 0)
                {
                    return(Ok(new
                    {
                        apiVersion = ApiVersion,
                        data = viewModel,
                        message = General.OK_MESSAGE,
                        statusCode = General.OK_STATUS_CODE
                    }));
                }
                else
                {
                    int clientTimeZoneOffset = int.Parse(Request.Headers["x-timezone-offset"].First());

                    //BankExpenditureNotePDFTemplate PdfTemplate = new BankExpenditureNotePDFTemplate();
                    //MemoryStream stream = PdfTemplate.GeneratePdfTemplate(model, clientTimeZoneOffset);
                    MemoryStream stream = facade.GeneratePdfTemplate(model, clientTimeZoneOffset);

                    return(new FileStreamResult(stream, "application/pdf")
                    {
                        FileDownloadName = $"Bank Expenditure Note {model.DocumentNo}.pdf"
                    });
                }
            }
            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));
            }
        }
Exemplo n.º 5
0
        public async Task <IActionResult> Post([FromBody] BankExpenditureNoteViewModel 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));
            IValidateService validateService = (IValidateService)serviceProvider.GetService(typeof(IValidateService));

            try
            {
                validateService.Validate(viewModel);

                BankExpenditureNoteModel model = mapper.Map <BankExpenditureNoteModel>(viewModel);

                int result = await facade.Create(model, identityService);

                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));
            }
        }