public int PayOrder(int invoiceId, int orderId, PaymentTypeViewModel payment) { try { Order order = _orderRepository.GetById(orderId); Invoice invoice = _invoiceRepository.GetById(invoiceId); invoice.PaymentType = (PaymentType)payment; if (payment == PaymentTypeViewModel.Cash) { _invoiceRepository.Insert( new Invoice { Date = DateTime.Now, PaymentType = PaymentType.Cash, Total = invoice.Total, OrderId = order.Id } ); } return(_invoiceRepository.Insert(invoice)); } catch (Exception ex) { string message = ex.Message; throw new Exception(message); } }
public IActionResult Update([FromBody] CrudViewModel <PaymentTypeViewModel> payload) { PaymentTypeViewModel value = payload.value; var result = _functionalService .Update <PaymentTypeViewModel, PaymentType>(value, Convert.ToInt32(value.PaymentTypeId)); return(Ok()); }
// GET: Orders/Checkout public async Task <IActionResult> Checkout(int?id) { if (id == null) { return(NotFound()); } var currentUser = await GetCurrentUserAsync(); List <PaymentType> paymentTypes = _context.PaymentType.Where(pt => pt.UserId == currentUser.Id).ToList(); PaymentTypeViewModel model = new PaymentTypeViewModel(paymentTypes); return(View(model)); }
public IHttpActionResult Put(Guid key, PaymentTypeViewModel delta) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } using (var unitOfWork = _unitOfWorkManager.NewUnitOfWork()) { _paymentType.UpdatePaymentType(delta); unitOfWork.Commit(); return(StatusCode(HttpStatusCode.OK)); } }
public async Task <PaymentTypeViewModel> PrepareEditModel(Guid id) { var type = await _appService.GetById(id); if (type == null) { throw new Exception("Not found"); } var model = new PaymentTypeViewModel() { DisplayOrder = type.DisplayOrder, TypeName = type.TypeName, Id = type.Id }; return(model); }
public bool UpdatePaymentType(PaymentTypeViewModel model) { var PaymentType = Find(model.Id.Value); if (PaymentType != null) { PaymentType.Name = model.Name; PaymentType.LastModifiedDate = DateTime.Now; PaymentType.User = _userRepository.Find(HttpContext.Current.User.Identity.GetUserId()); Update(PaymentType); return(true); } else { throw new Exception("Không tìm thấy hình thức thanh toán này"); } }
public PaymentType AddPaymentType(PaymentTypeViewModel model) { if (Queryable().Any(x => x.Name.ToLower().Contains(model.Name.ToLower()) && x.Delete == false)) { throw new Exception("Đã tồn tại hình thức thanh toán này"); } else { var result = new PaymentType(); result.Name = model.Name; result.CreatedDate = DateTime.Now; result.LastModifiedDate = DateTime.Now; result.User = _userRepository.Find(HttpContext.Current.User.Identity.GetUserId()) ?? _userRepository.GetAll().FirstOrDefault(); Insert(result); return(result); } }
public PaymentTypeViewModel GetById(int PaymentTypeId) { var paymentType = new PaymentType(); var _paymentTypeViewModel = new PaymentTypeViewModel(); var _objPaymentType = _restaurantDBEntities.PaymentTypes .Where(o => o.PaymentTypeId == PaymentTypeId) .FirstOrDefault(); paymentType.PaymentTypeId = _objPaymentType.PaymentTypeId; paymentType.PaymentTypeName = _objPaymentType.PaymentTypeName; //MapsterMapper _paymentTypeViewModel.PaymentTypeId = paymentType.PaymentTypeId; _paymentTypeViewModel.PaymentTypeName = paymentType.PaymentTypeName; return(_paymentTypeViewModel); }
// POST: odata/Warehouse public IHttpActionResult Post(PaymentTypeViewModel delta) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } // TODO: Add create logic here. using (var unitOfWork = _unitOfWorkManager.NewUnitOfWork()) { var result = _paymentType.AddPaymentType(delta); unitOfWork.Commit(); var resultObject = new PaymentTypeViewModel() { Id = result.Id, Name = result.Name }; return(Created(resultObject)); } }
public async Task <IActionResult> Create(PaymentType paymentType) { var user = await GetCurrentUserAsync(); // Link the active customer's id to the newly created payment type paymentType.User = user; //if the payment type received from the form is valid, post it to the database and redirect the customer to the Order/Cart view if (ModelState.IsValid) { //Add the payment type to the database context.Add(paymentType); await context.SaveChangesAsync(); return(RedirectToAction("Cart", "Order")); } //otherwise, recreate the payment/create view, which will display an error message based on the invalidity in the model PaymentTypeViewModel model = new PaymentTypeViewModel(context); return(View(model)); }
public async Task <IActionResult> Update([FromBody] PaymentTypeViewModel value) { if (ModelState.IsValid) { var ret = await this._unitOfWork.PaymentTypes.Save(new PaymentType { PaymentTypeId = 1, PaymentTypeCode = value.Code, BranchId = Guid.NewGuid(), PaymentTypeName = value.Name, Note = value.Note, CreatedBy = userId, UpdatedBy = userId, CreatedDate = DateTime.Now, UpdatedDate = DateTime.Now }); return(Ok(ret)); } return(BadRequest(ModelState)); }
public async Task <ActionResult> Create(PaymentTypeViewModel paymentTypeViewModel) { if (!ModelState.IsValid) { return(View(new PaymentType { DateCreated = DateTime.Now, Description = paymentTypeViewModel.Description, AccountNumber = paymentTypeViewModel.AccountNumber, ExpirationDate = paymentTypeViewModel.ExpirationDate })); } try { var user = await GetCurrentUserAsync(); var paymentTypeInstance = new PaymentType { DateCreated = DateTime.Now, Description = paymentTypeViewModel.Description, AccountNumber = paymentTypeViewModel.AccountNumber, ExpirationDate = paymentTypeViewModel.ExpirationDate }; paymentTypeInstance.UserId = user.Id; _context.PaymentType.Add(paymentTypeInstance); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } catch { return(View()); } }
//update the payment type of order public async Task <IActionResult> CompleteOrder(PaymentTypeViewModel model) { if (model.PaymentType.PaymentTypeId == 0) { return(NotFound()); } var user = await GetCurrentUserAsync(); Order currentOrder = _context.Order .Include(o => o.User) .Include(o => o.PaymentType) .Where(o => o.UserId == user.Id) .Where(o => o.PaymentType == null).ToList().FirstOrDefault(); if (currentOrder != null) { currentOrder.PaymentTypeId = model.PaymentType.PaymentTypeId; _context.Update(currentOrder); await _context.SaveChangesAsync(); } return(View()); }
public InvoiceViewModel GetInvoiceById(int id, int orderId, PaymentTypeViewModel model) { throw new NotImplementedException(); }
public PaymentTypeRepository() { _paymentTypeViewModel = new PaymentTypeViewModel(); _restaurantDBEntities = new RestaurantDBEntities(); }
public IActionResult Create() { PaymentTypeViewModel model = new PaymentTypeViewModel(context); return(View(model)); }