public IActionResult Create(CreateSaleViewModel model) { if (ModelState.IsValid) { Sale sale = new Sale() { date1 = DateTime.Now, id_client = _context.FindUser(User.Identity.Name).id_client.Value, id_car = model.id_car, id_payment = null, date2 = model.date2, date3 = model.date3, summ = model.summ, status = "Обрабатывается" }; int canadd = _context.CanAddSale(sale); if (canadd == 1) //проверка на корректность { ModelState.AddModelError("", "Неверное время аренды."); return(View(model)); } else if (canadd == 2) //проверка на занятость { ModelState.AddModelError("", "В это время автомобиль забронирован."); return(View(model)); } int id_sale = _context.AddSale(sale);; if (id_sale != 0) { sale = _context.FindSale(id_sale); _context.CreateEventStatusCar(sale); return(RedirectToAction("Index", "Home")); } else { ModelState.AddModelError("", "Ошибка"); } } return(View(model)); }
public ActionResult ViewSale(int? id = 0) { ViewBag.Customers = _context.Customers.ToList(); ViewBag.FoodItems = _context.FoodItems.ToList(); Sale sale = _context.Sale.Find(id); CreateSaleViewModel vm = new CreateSaleViewModel(); vm.Sale_FoodItems = new List<Sale_FoodItem>(); vm.Customer_Id = sale.Customer_Id; vm.Amount = sale.Amount; vm.Sale_Id = sale.Sale_Id; vm.Amount_Pay = sale.Amount_Pay; vm.Grand_Total = sale.Grand_Total; vm.Left_Amount = sale.Left_Amount; vm.Remaining_Amount = sale.Remaining_Amount; vm.Created_Date = sale.Created_Date; vm.Is_Paid = sale.Is_Paid == true ? "Yes" : "No"; foreach (var item in _context.Sale_FoodItems.Where(m => m.Sale_Id == sale.Sale_Id)) { Sale_FoodItem foodItem = new Sale_FoodItem(); foodItem.Amount = item.Amount; foodItem.Quantity = item.Quantity; foodItem.Rate = item.Rate; foodItem.Id = item.Sale_FoodItem_Id; foodItem.Name = item.Food_Item.Name; vm.Sale_FoodItems.Add(foodItem); } return View(vm); }
public ActionResult Create(int?page) { var model = new CreateSaleViewModel(); ViewBag.CurrentPage = page; return(View(model)); }
// GET: SalesController/Create public ActionResult Create() { CreateSaleViewModel createSaleViewModel = new CreateSaleViewModel(); createSaleViewModel.CarList = _carService.All(); return(View(createSaleViewModel)); }
public void CreateNewSale(string userId, CreateSaleViewModel model) { using (var context = new HardwareShopContext()) { var user = context.Users.FirstOrDefault(u => u.Id == userId); var cart = context.Carts.FirstOrDefault(c => c.UserId == userId && c.IsSold == false); var sale = Mapper.Instance.Map <CreateSaleViewModel, Sale>(model); sale.Cart = cart; sale.SaleDate = DateTime.Now; sale.TotalPrice = cart.Items.Sum(i => i.Price); cart.IsSold = true; foreach (var item in cart.Items) { item.Quantity--; } user.Carts.Add(new Cart()); context.Sales.Add(sale); context.SaveChanges(); context.Items.Where(i => i.Quantity < 1).Update(i => new Item { ItemStatus = ItemStatus.OutOfStock }); context.SaveChanges(); } }
public CreateSaleViewModel Create(SaleViewModel saleViewModel) { var query = $"EXEC CreateSale '{saleViewModel.UserId}', '{saleViewModel.CardId}', 'false', '{DateTime.UtcNow}'; "; CreateSaleViewModel createSaleViewModel = _context.CreateSaleViewModel.FromSql(query).FirstOrDefault(); return(createSaleViewModel); }
public RedirectToRouteResult Create(CreateSaleViewModel viewModel) { var model = viewModel.Sale; _createCommand.Execute(model); return(RedirectToAction("index", "sales")); }
public Sale Edit(int id, CreateSaleViewModel sale) { Sale editidSale = new Sale() { Id = id, Buyer = sale.Buyer, Seller = sale.Seller, Car = sale.Car, TransactionDate = sale.TransactionDate }; return(_saleRepo.Update(editidSale)); }
public IActionResult Create() { var createModel = new CreateSaleViewModel { ProductTitles = new SelectList(_productService.GetTitles(), "Id", "Title") }; return(View(createModel)); }
public IActionResult Create(CreateSaleViewModel createVM) { if (ModelState.IsValid) { var saleDTO = _mapper.Map <SaleBindingModel, SaleDTO>(createVM.Sale); _saleService.Add(saleDTO); return(RedirectToAction(nameof(Items))); } createVM.ProductTitles = new SelectList(_productService.GetTitles(), "Id", "Title"); return(View(createVM)); }
public Sale Add(CreateSaleViewModel createSaleViewModel) { createSaleViewModel.Car = _carService.FindBy(createSaleViewModel.Car.Id); if (createSaleViewModel.Car == null) { return(null); } Sale sale = _saleRepo.Create(createSaleViewModel.Buyer, createSaleViewModel.Seller, createSaleViewModel.Car, createSaleViewModel.TransactionDate); return(sale); }
public ActionResult CreateNewSale(CreateSaleViewModel model) { if (!this.ModelState.IsValid) { return this.View(model); } var userId = this.User.Identity.GetUserId(); this.saleService.CreateNewSale(userId, model); return this.RedirectToAction("Index", "Home"); }
public void TestGetCreateShouldReturnCreateSaleViewModel() { var viewModel = new CreateSaleViewModel(); _mocker.GetMock <ICreateSaleViewModelFactory>() .Setup(p => p.Create()) .Returns(viewModel); var viewResult = _controller.Create(); var result = (CreateSaleViewModel)viewResult.Model; Assert.That(result, Is.EqualTo(viewModel)); }
public RedirectToRouteResult Create(CreateSaleViewModel viewModel) { var model = new CreateSaleModel() { CustomerId = viewModel.Sale.CustomerId, EmployeeId = viewModel.Sale.EmployeeId, ProductId = viewModel.Sale.ProductId, Quantity = viewModel.Sale.Quantity }; _createCommand.Execute(model); return(RedirectToAction("index", "sales")); }
public void TestPostCreateShouldReturnExecuteCreateSaleCommand() { var model = new CreateSaleModel(); var viewModel = new CreateSaleViewModel() { Sale = model }; _controller.Create(viewModel); _mocker.GetMock <ICreateSaleCommand>() .Verify(p => p.Execute(model)); }
public IActionResult Edit(int id, CreateSaleViewModel editSale) { if (ModelState.IsValid) { Sale sale = _saleService.Edit(id, editSale); if (sale != null) { return(RedirectToAction(nameof(Index))); } ModelState.AddModelError("msg", "Database problems"); } return(View(editSale)); }
// GET: Sales/Create public ActionResult Create(int? id = 0) { ViewBag.Customers = _context.Customers.ToList(); ViewBag.FoodItems = _context.FoodItems.ToList(); CreateSaleViewModel sale = new CreateSaleViewModel(); sale.Sale_FoodItems = new List<Sale_FoodItem>(); if (id != 0) { Customer customer = _context.Customers.Find(id); sale.Customer_Id = id.Value; sale.Remaining_Amount = customer.Remaining_Amount; } //sale.Remaining_Amount = _context.Sale.Where(m => m.Customer_Id == id).Sum(c => c.Remaining_Amount); return View(sale); }
public ActionResult Create(CreateSaleViewModel model, int?page) { if (!ModelState.IsValid) { return(View(model)); } try { _saleService.AddSale(_mapper.Map <CreateSaleViewModel, SaleDTO>(model)); return(RedirectToAction("Index", new { page = page })); } catch { return(View("Error")); } }
public IActionResult Create(int id_c) { int?id_cl = _context.FindUser(User.Identity.Name).id_client; if (id_cl != null) { Car car = _context.FindCar(id_c); var model = new CreateSaleViewModel() { id_car = id_c, rentprice = car.Price }; return(View(model)); } else { return(RedirectToAction("Create", "Client")); } }
public ActionResult Create(CreateSaleViewModel createSale) { if (ModelState.IsValid) { Sale sale = _saleService.Add(createSale); if (sale == null) { ModelState.AddModelError("msg", "Database problems"); return(View(createSale)); } return(RedirectToAction(nameof(Index))); } else { return(View(createSale)); } }
public CreateSaleViewModel createSaleViewModel() { CreateSaleViewModel viewModel = new CreateSaleViewModel(); viewModel.createSaleModel = new CreateSaleModel(); viewModel.Products = new List <SelectListItem>(); viewModel.AddedProducts = new List <ProductListItemModel>(); var ProductList = getProductListQuery.Execute(); foreach (var i in ProductList) { SelectListItem item = new SelectListItem(); item.Text = i.ProductName; item.Value = i.ProductID.ToString(); viewModel.Products.Add(item); } return(viewModel); }
public CreateSaleViewModel Create() { var employees = _employeesQuery.Execute(); var customers = _customersQuery.Execute(); var products = _productsQuery.Execute(); var viewModel = new CreateSaleViewModel(); viewModel.Employees = employees .Select(p => new SelectListItem() { Value = p.Id.ToString(), Text = p.Name }) .ToList(); viewModel.Customers = customers .Select(p => new SelectListItem() { Value = p.Id.ToString(), Text = p.Name }) .ToList(); viewModel.Products = products .Select(p => new SelectListItem() { Value = p.Id.ToString(), Text = p.Name + " ($" + p.UnitPrice + ")" }) .ToList(); viewModel.Sale = new CreateSaleModel(); return(viewModel); }
public async Task <object> Create([FromBody] SaleViewModel saleViewModel) { CreateSaleViewModel createSaleViewModel = new CreateSaleViewModel(); try { createSaleViewModel = _saleRepository.Create(saleViewModel); } catch (Exception ex) { result = false; error = ex.Message; } return(new SingleResponse <CreateSaleViewModel> { Message = "Sale created successfully", DidError = false, ErrorMessage = string.Empty, Token = string.Empty, Model = createSaleViewModel }); }
public ActionResult CreateNewSale() { var model = new CreateSaleViewModel(); return this.View(model); }
public async Task <IActionResult> Create([Bind("SellerID,ProductIDsText,ProductQuantityText")] CreateSaleViewModel sv) { if (string.IsNullOrEmpty(sv.ProductIDsText) || !sv.CastVariables()) { return(View("GeneralError", new GeneralErrorViewModel { Text = "დაფიქსირდა შეცდომა მონაცემების დამუშავებისას!" })); } if (sv.ProductIDs is null || sv.ProductIDs.Count == 0) { return(View("GeneralError", new GeneralErrorViewModel { Text = "თქვენ არ გაქვთ არჩეული პროდუქტი!" })); } Sale sale = new Sale(); var consultant = _context.Consultants.FirstOrDefault(c => c.ID == sv.SellerID); if (consultant == null) { return(View("GeneralError", new GeneralErrorViewModel { Text = "კონსულტანტი ვერ მოიძებნა!" })); } List <SaleItem> saleItems = new List <SaleItem>(); var products = _context.Products.Where(p => sv.ProductIDs.Contains(p.ID)).ToList(); float totalPrice = 0; for (int i = 0; i < sv.ProductIDs.Count; i++) { var prod = products.FirstOrDefault(p => p.ID == sv.ProductIDs[i]); saleItems.Add(new SaleItem() { Code = prod.Code, Price = prod.Price, Title = prod.Title, Quantity = sv.ProductQuantity[i] }); totalPrice += prod.Price * sv.ProductQuantity[i]; } sale.TotalPrice = totalPrice; var sellerInfo = new { PID = consultant.PID, FullName = consultant.GetFullName() }; sale.SellerInfo = JsonConvert.SerializeObject(sellerInfo); sale.Description = JsonConvert.SerializeObject(saleItems); sale.SaleDate = DateTime.Now; if (ModelState.IsValid) { _context.Add(sale); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(sale)); }
private void OpenSaleView(object parameter) { BusinessContext.Instance.BeginOperation(); var viewModel = new CreateSaleViewModel(new CreateSaleView(), 0); Terminal.Instance.Client.ShowView(viewModel.View); }
public ActionResult Create(CreateSaleViewModel CreateSaleViewModel) { try { var Customer = _context.Customers.Where(m => m.Customer_Id == CreateSaleViewModel.Customer_Id).FirstOrDefault(); Customer.Remaining_Amount = (Customer.Remaining_Amount + CreateSaleViewModel.Amount)-CreateSaleViewModel.Amount_Pay; _context.Entry(Customer).State = EntityState.Modified; _context.SaveChanges(); Sale sale = new Sale(); sale.Created_Date = DateTime.UtcNow; sale.Modified_Date = DateTime.UtcNow; sale.Customer_Id = CreateSaleViewModel.Customer_Id; sale.Amount = CreateSaleViewModel.Amount; sale.Remaining_Amount = Customer.Remaining_Amount; sale.Left_Amount = CreateSaleViewModel.Left_Amount; sale.Grand_Total = CreateSaleViewModel.Grand_Total; sale.Is_Active = true; sale.Is_Deleted = false; sale.Is_Paid = CreateSaleViewModel.Amount == 0 ? true : false; sale.Amount_Pay = CreateSaleViewModel.Amount_Pay; _context.Sale.Add(sale); _context.SaveChanges(); var Sale_ID = _context.Sale.OrderByDescending(m => m.Sale_Id).FirstOrDefault().Sale_Id; if (CreateSaleViewModel.Sale_FoodItems!=null) { foreach (var item in CreateSaleViewModel.Sale_FoodItems) { Sale_FoodItemRelation sale_FoodItem = new Sale_FoodItemRelation(); sale_FoodItem.Quantity = item.Quantity; sale_FoodItem.Rate = item.Rate; sale_FoodItem.Amount = item.Amount; sale_FoodItem.Sale_Id = Sale_ID; sale_FoodItem.Created_Date = DateTime.UtcNow; sale_FoodItem.Modified_Date = DateTime.UtcNow; sale_FoodItem.Food_Item_Id = _context.FoodItems.Where(m => m.Name == item.Name).FirstOrDefault().FoodItem_Id; _context.Sale_FoodItems.Add(sale_FoodItem); _context.SaveChanges(); } } var Amount_Pay = CreateSaleViewModel.Amount_Pay; // var sales = _context.Sale.Where(m => m.Customer_Id == CreateSaleViewModel.Customer_Id && m.Is_Paid == false).ToList(); // if (sales.Count() > 0 ) { // foreach (var item in sales) // { // Sale vm = _context.Sale.Where(m => m.Sale_Id == item.Sale_Id).FirstOrDefault(); // if (Amount_Pay > 0) // { // if (Amount_Pay >= vm.Remaining_Amount) // { // vm.Is_Paid = true; // Amount_Pay = Amount_Pay - vm.Remaining_Amount; // vm.Remaining_Amount = 0; // vm.Modified_Date = DateTime.UtcNow; // _context.Update(vm); // _context.SaveChanges(); // } // else // { // vm.Is_Paid = false; // vm.Remaining_Amount = vm.Remaining_Amount - Amount_Pay; // Amount_Pay = 0; // vm.Modified_Date = DateTime.UtcNow; // _context.Update(vm); // _context.SaveChanges(); // } // } // //vm.Remaining_Amount = CreateSaleViewModel.Remaining_Amount; // } //} return Json(Sale_ID, JsonRequestBehavior.AllowGet); } catch (Exception ex) { return RedirectToAction(nameof(Index)); } }
public void CreateSale([FromBody] CreateSaleViewModel viewModel) { _createSaleCommand.Execute(viewModel.Sale); }
public ActionResult Create(CreateSaleViewModel createSaleViewModel) { return(RedirectToAction("Index")); }