public IActionResult SaveEntity(BillViewModel billVm, List <BillDetailViewModel> BillDetails) { try { //if (!ModelState.IsValid) //{ // IEnumerable<ModelError> allErrors = ModelState.Values.SelectMany(v => v.Errors); // return new BadRequestObjectResult(allErrors); //} if (billVm.Id.ToString() == CommonConstants.DefaultGuid) { _billService.Add(billVm, out var billId); if (BillDetails != null) { foreach (var item in BillDetails) { item.BillId = billId; _billService.AddDetail(item); } } } else { _billService.Update(billVm, BillDetails); } _billService.Save(); return(new OkObjectResult(billVm)); } catch (Exception ex) { throw ex; } }
public ActionResult Post([FromBody] AddBillRequestModel model) { try { var bill = new Bill() { CreatedAt = today, Status = model.Status, UpdatedAt = today, Name = model.Name, Description = model.Description, Amount = model.Amount, StartDate = model.StartDate, EndDate = model.EndDate, PaymentCategoryId = model.PaymentCategoryId, BuildingId = model.BuildingId, }; _billService.Add(bill); response.StatusCode = StatusCodes.Status200OK; response.Status = "OK"; response.Message = "Pago agregado"; return(Ok(response)); } catch (Exception e) { response.StatusCode = StatusCodes.Status400BadRequest; response.Status = "BAD REQUEST"; response.Message = e.Message; return(BadRequest(response)); } }
public ActionResult PostBill(BillDTO billDto) { _billService.Add(billDto); //var bill = _billService.GetBy(billDto.BillId); return(Ok(new { success = true, message = "Tạo hóa đơn thành công" })); }
public async Task <IActionResult> Checkout(CheckoutViewModel model) { var session = HttpContext.Session.Get <List <ShoppingCartViewModel> >(CommonConstants.CartSession); if (ModelState.IsValid) { if (session != null) { var details = new List <BillDetailViewModel>(); foreach (var item in session) { details.Add(new BillDetailViewModel() { Product = item.Product, Price = item.Price, Quantity = item.Quantity, ProductId = item.Product.Id }); } var billViewModel = new BillViewModel() { CustomerMobile = model.CustomerMobile, BillStatus = BillStatus.New, CustomerAddress = model.CustomerAddress, CustomerName = model.CustomerName, CustomerMessage = model.CustomerMessage, BillDetails = details, CustomerId = User.Identity.IsAuthenticated == true ? ((ClaimsIdentity)User.Identity).GetSpecificClaim("UserId") : null }; _billService.Add(billViewModel); try { _billService.Save(); var content = await _viewRenderService.RenderToStringAsync("Cart/_OrderMail", billViewModel); //Send mail await _emailSender.SendEmailAsync(_configuration["MailSettings:AdminMail"], "Đơn hàng mới", content); ViewData["Success"] = true; } catch (Exception ex) { ViewData["Success"] = false; ModelState.AddModelError("", ex.Message); } } } model.Carts = session; return(View(model)); }
public async Task <IActionResult> Add([FromBody] BillViewModel billVmPost) { var hasPermission = await _authorizationService.AuthorizeAsync(User, "BILL", Operations.Create); if (hasPermission.Succeeded == false) { return(new BadRequestObjectResult(CommonConstants.Forbidden)); } if (ModelState.IsValid) { try { decimal totalPayment = 0; BillViewModel billVm = billVmPost; var listBillDetails = new List <BillDetailViewModel>(); decimal totalMoneyOriginnal = 0; foreach (var item in billVm.BillDetails) { totalPayment = totalPayment + item.Quantity * item.Price; totalMoneyOriginnal = totalMoneyOriginnal + item.Quantity * item.OriginalPrice; listBillDetails.Add(new BillDetailViewModel() { ProductId = item.ProductId, Quantity = item.Quantity, Price = item.Price, SizeId = item.SizeId, ColorId = item.ColorId, OriginalPrice = item.OriginalPrice }); } billVm.TotalMoneyPayment = totalPayment; billVm.TotalMoneyOrder = totalPayment; billVm.TotalOriginalPrice = totalMoneyOriginnal; billVm.FeeShipping = 0; billVm.BillDetails = listBillDetails; int billId = _billService.Add(billVm); billVm.Id = billId; billVm.DateCreated = DateTime.Now; return(new OkObjectResult(billVm)); } catch (Exception ex) { return(new BadRequestObjectResult(ex.Message)); } } return(new BadRequestObjectResult(ModelState)); }
public IActionResult SaveEntity(BillViewModel billVm) { if (!ModelState.IsValid) { IEnumerable <ModelError> allErrors = ModelState.Values.SelectMany(v => v.Errors); return(new BadRequestObjectResult(allErrors)); } if (billVm.Id == Guid.Empty) { _billService.Add(billVm); } else { _billService.Update(billVm); } _billService.Save(); return(new OkObjectResult(billVm)); }
public HttpResponseMessage Create(HttpRequestMessage request, Bill bill) { return(CreateHttpResponse(request, () => { HttpResponseMessage response = null; if (!ModelState.IsValid) { response = request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } else { var result = billService.Add(bill); billService.SaveChanges(); response = request.CreateResponse(HttpStatusCode.Created, result); } return response; })); }
public void Bill_Service_Create() { Bill bill = new Bill(); int id = 1; bill.CustomerName = "Test bill"; bill.CreatedDate = DateTime.Now; bill.CreatedBy = "Test"; bill.Content = "Trung rong hap sa"; bill.Status = true; _mockRepository.Setup(m => m.Add(bill)).Returns((Bill p) => { p.ID = 1; return(p); }); var result = _categoryService.Add(bill); Assert.IsNotNull(result); Assert.AreEqual(1, result.ID); }
public async Task Post([FromBody] AddBillDto dto) { dto.UserId = User.Identity.Name; await _billService.Add(dto); }
public HttpResponseMessage Create(HttpRequestMessage request, BookViewModel bookVm) { return(CreateHttpResponse(request, () => { HttpResponseMessage response = null; if (!ModelState.IsValid) { response = request.CreateResponse(HttpStatusCode.BadRequest, ModelState); } else { //Thêm mới khách hàng var newCustomer = new Customer(); newCustomer.Name = bookVm.NameCustomer; newCustomer.PhoneNumber = bookVm.PhoneCustomer; newCustomer.Email = bookVm.MailCustomer; newCustomer.Address = bookVm.AddressCustomer; newCustomer.isDel = false; //AddCustommer _customerService.Add(newCustomer); _customerService.Save(); //Thêm mới book var newBook = new Booking(); newBook.IDCar = bookVm.IDCar; newBook.IDCustomer = newCustomer.ID; newBook.IDSeat = bookVm.IDSeat; newBook.IDSeatNo = bookVm.IDSeatNo; newBook.DateBook = DateTime.Now; newBook.CreatedBy = bookVm.CreatedBy; newBook.CreatedDate = DateTime.Now; newBook.MetaDescription = bookVm.MetaDescription; newBook.Status = true; //AddBoook _bookService.Add(newBook); _bookService.Save(); //NewBill var newBill = new Bill(); newBill.CustomerName = bookVm.NameCustomer; newBill.CustomerPhone = bookVm.PhoneCustomer; newBill.dateBook = bookVm.Date; newBill.DatedBill = DateTime.Now; newBill.IDCar = bookVm.IDCar; newBill.SeatName = bookVm.SeatNoName; newBill.CountMoney = "210000"; newBill.CustomerMail = bookVm.MailCustomer; newBill.Status = false; //AddBill _billService.Add(newBill); _billService.Save(); //update SeatNo var dbSeatNo = _seatnoService.GetById(bookVm.IDSeatNo); dbSeatNo.Status = true; _seatnoService.Update(dbSeatNo); _seatnoService.Save(); var responseData = Mapper.Map <Customer, CustomerViewModel>(newCustomer); response = request.CreateResponse(HttpStatusCode.Created, responseData); } return response; })); }
public async Task <IActionResult> Checkout(BillViewModel billVm, decimal feeShipping, decimal totalMoneyOrder, decimal balanceForBill, decimal totalMoneyPayment) { try { var shoppingCart = HttpContext.Session.GetList <ShoppingCardViewModel>(CommonConstants.SesstionCart); BillViewModel billViewModel; billViewModel = billVm; billViewModel.FeeShipping = feeShipping; billViewModel.TotalMoneyOrder = totalMoneyOrder; billViewModel.TotalMoneyPayment = totalMoneyPayment; billViewModel.BillStatus = Data.Enums.BillStatus.New; billViewModel.Status = Data.Enums.Status.Active; if (User.Identity.IsAuthenticated) { var user = await _userManager.FindByNameAsync(User.Identity.Name); billViewModel.BalanceForBill = balanceForBill; billViewModel.CustomerId = user.Id; } var listBillDetails = new List <BillDetailViewModel>(); decimal totalOriginalPrice = 0; foreach (var item in shoppingCart) { decimal salePrice; if (item.ProductVm.PromotionPrice.HasValue) { salePrice = (decimal)item.ProductVm.PromotionPrice; } else { salePrice = item.ProductVm.Price; } BillDetailViewModel billDetailVm = new BillDetailViewModel() { ProductId = item.ProductId, ColorId = item.ColorVm.Id, SizeId = item.SizeVm.Id, Quantity = item.Quantity, Price = salePrice, OriginalPrice = item.ProductVm.OriginalPrice }; totalOriginalPrice = totalOriginalPrice + item.Quantity * item.ProductVm.OriginalPrice; listBillDetails.Add(billDetailVm); } billViewModel.BillDetails = listBillDetails; billViewModel.TotalOriginalPrice = totalOriginalPrice; int billId = _billService.Add(billViewModel); billViewModel.Id = billId; billViewModel.DateCreated = DateTime.Now; if (User.Identity.IsAuthenticated) { AppUser appUser = await _userManager.FindByNameAsync(User.Identity.Name); if (totalMoneyPayment > 0) { appUser.Balance = balanceForBill; } else { appUser.Balance = appUser.Balance - totalMoneyOrder - feeShipping + balanceForBill; } await _userManager.UpdateAsync(appUser); } HttpContext.Session.SetList <ShoppingCardViewModel>(CommonConstants.SesstionCart, null); return(new OkObjectResult(new { status = true, billVm = billViewModel })); } catch { return(new OkObjectResult(new { status = false })); } }
public async Task <IActionResult> Checkout(CheckoutViewModel model) { try { var session = HttpContext.Session.Get <List <ShoppingCartViewModel> >(CommonConstants.CartSession); if (ModelState.IsValid) { if (session != null) { var details = new List <BillDetailViewModel>(); foreach (var item in session) { details.Add(new BillDetailViewModel() { Price = item.Price, Color = item.Color, ProductName = item.Product.Name, Code = item.Product.Code, //ColorId = item.Color.Id, Quantity = item.Quantity, ProductId = item.Product.Id }); } var billViewModel = new BillViewModel() { CustomerMobile = model.CustomerMobile, BillStatus = BillStatus.New, CustomerAddress = model.CustomerAddress, CustomerName = model.CustomerName, ShipMobile = model.ShipMobile, ShipAddress = model.ShipAddress, ShipName = model.ShipName, Status = Infrastructure.Enums.Status.Actived, PaymentMethod = model.PaymentMethod, //BillDetails = details }; if (User.Identity.IsAuthenticated == true) { billViewModel.CustomerId = Guid.Parse(User.GetSpecificClaim("UserId")); } _billService.Add(billViewModel, out var billId); if (details != null) { foreach (var item in details) { item.BillId = billId; _billService.AddDetail(item); } } try { _billService.Save(); //var content = await _viewRenderService.RenderToStringAsync("Cart/_BillMail", billViewModel); //Send mail //await _emailSender.SendEmailAsync(_configuration["MailSettings:AdminMail"], "Đặt hàng từ Rèm Đức Trung", content); ViewData["Success"] = true; } catch (Exception ex) { ViewData["Success"] = false; ModelState.AddModelError("", ex.Message); } } } model.Carts = session; return(View(model)); } catch (Exception ex) { throw ex; } }