public async Task <IActionResult> Create([Bind("RestaurantId,Title,Phone,LocationId,CreatedDateTime,LastModifiedDateTime")] Restaurant restaurant) { if (ModelState.IsValid) { restaurant.CreatedDateTime = DateTime.Now; restaurant.LastModifiedDateTime = DateTime.Now; _context.Add(restaurant); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } var selectList = _context.Location .Include(c => c.Street) .ThenInclude(c => c.District) .ThenInclude(c => c.City) .Select(c => new { LocationId = c.LocationId, Descr = $"{c.Street.District.City.City1}, {c.Street.District.District1}, " + $"{c.Street.Street1}, {c.BuildingNbr}/{c.Room})" }); ViewData["LocationId"] = new SelectList(selectList, "LocationId", "Descr", restaurant.LocationId); return(View(restaurant)); }
public async Task <IActionResult> Create([Bind("DeliveryId,OrderId,CourierId,LocationId,Description,StartTime,EndTime,CreatedDateTime,LastModifiedDateTime,Weight")] Delivery delivery) { if (ModelState.IsValid) { delivery.CreatedDateTime = DateTime.Now; delivery.LastModifiedDateTime = DateTime.Now; delivery.Status = DeliveryStatus.Created; _context.Add(delivery); await _context.SaveChangesAsync(); return(RedirectToRoute(new { controller = "Deliveries", action = "Details", id = delivery.DeliveryId })); } ViewData["CourierId"] = new SelectList(_context.Courier, "CourierId", "Name", delivery.CourierId); var selectList = _context.Location .Include(c => c.Street) .ThenInclude(c => c.District) .ThenInclude(c => c.City) .Select(c => new { LocationId = c.LocationId, Descr = $"{c.Street.District.City.City1}, {c.Street.District.District1}, " + $"{c.Street.Street1}, {c.Street.Street1}, {c.BuildingNbr}/{c.Room})" }); ViewData["LocationId"] = new SelectList(selectList, "LocationId", "Descr", delivery.LocationId); ViewData["OrderId"] = new SelectList(_context.Order, "OrderId", "OrderId", delivery.OrderId); return(View(delivery)); }
public async Task <IActionResult> Create([Bind("RestaurantDishRelationId,RestaurantId,DishId,Price,CreatedDateTime,LastModifiedDateTime")] RestaurantDishRelation restaurantDishRelation) { if (ModelState.IsValid) { restaurantDishRelation.CreatedDateTime = DateTime.Now; restaurantDishRelation.LastModifiedDateTime = DateTime.Now; _context.Add(restaurantDishRelation); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["DishId"] = new SelectList(_context.Dish, "DishId", "Title", restaurantDishRelation.DishId); var selectList = _context.Restaurant .Include(r => r.Location) .ThenInclude(c => c.Street) .ThenInclude(c => c.District) .ThenInclude(c => c.City) .Select(c => new { RestaurantId = c.RestaurantId, Descr = $"{c.Title} (id:{c.RestaurantId}, {c.Location.Street.District.City.City1})" }); ViewData["RestaurantId"] = new SelectList(selectList, "RestaurantId", "Descr", restaurantDishRelation.RestaurantId); return(View(restaurantDishRelation)); }
public async Task <IActionResult> Create([Bind("InvoiceId,OrderId,DeliveryPrice,TotalAmt,Discount,DateTime,CreatedDateTime,LastModifiedDateTime")] Invoice invoice) { if (ModelState.IsValid) { var order = _context.Order .Include(o => o.OrderLine) .ThenInclude(o => o.RestaurantDishRelation) .Include(o => o.Delivery) .ThenInclude(o => o.Courier) .ThenInclude(o => o.CourierType) .First(o => o.OrderId == invoice.OrderId); invoice.CreatedDateTime = DateTime.Now; invoice.LastModifiedDateTime = DateTime.Now; invoice.TotalAmt = order.OrderLine.Sum(o => o.Quantity * o.RestaurantDishRelation.Price); invoice.TotalAmt += order.Delivery.FirstOrDefault()?.Courier.CourierType.Rate ?? 0; invoice.TotalAmt = invoice.TotalAmt * (100m - invoice.Discount) / 100.0m; _context.Add(invoice); await _context.SaveChangesAsync(); return(RedirectToRoute(new { controller = "Invoices", action = "Details", id = invoice.InvoiceId })); } ViewData["OrderId"] = new SelectList(_context.Order, "OrderId", "OrderId", invoice.OrderId); return(View(invoice)); }
public async Task <IActionResult> Create([Bind("SalaryPaymentId,CourierId,StartPeriodDate,EndPeriodDate,DeliveriesCount,PaymentForDeliveries,Premium,FineAmt,PaymentAmt,CreatedDateTime,LastModifiedDateTime")] SalaryPayment salaryPayment) { if (ModelState.IsValid) { salaryPayment.CreatedDateTime = DateTime.Now; salaryPayment.LastModifiedDateTime = DateTime.Now; var deliveriesCount = _context .Delivery .Include(d => d.Courier) .ThenInclude(d => d.CourierType) .Where( d => d.CourierId == salaryPayment.CourierId && d.StartTime >= salaryPayment.StartPeriodDate && d.StartTime <= salaryPayment.EndPeriodDate && d.EndTime >= salaryPayment.StartPeriodDate && d.EndTime <= salaryPayment.EndPeriodDate) .Count(); var courier = _context.Courier .Include(c => c.CourierType) .First(c => c.CourierId == salaryPayment.CourierId); salaryPayment.DeliveriesCount = deliveriesCount; salaryPayment.PaymentForDeliveries = deliveriesCount * courier.CourierType.Rate; salaryPayment.PaymentAmt = salaryPayment.PaymentForDeliveries + salaryPayment.Premium.GetValueOrDefault(0) - salaryPayment.FineAmt.GetValueOrDefault(0); _context.Add(salaryPayment); await _context.SaveChangesAsync(); return(RedirectToRoute(new { controller = "SalaryPayments", action = "Details", id = salaryPayment.SalaryPaymentId })); } ViewData["CourierId"] = new SelectList(_context.Courier, "CourierId", "Name", salaryPayment.CourierId); return(View(salaryPayment)); }
public async Task <IActionResult> Create([Bind("CustomerId,Name,Surname,Phone,CreatedDateTime,LastModifiedDateTime")] Customer customer) { if (ModelState.IsValid) { customer.CreatedDateTime = DateTime.Now; customer.LastModifiedDateTime = DateTime.Now; _context.Add(customer); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(customer)); }
public async Task <IActionResult> Create([Bind("DishId,Title,Quantity,UnitOfMeasureId,DishTypeId,Description,CreatedDateTime,LastModifiedDateTime,Cost")] Dish dish) { if (ModelState.IsValid) { dish.CreatedDateTime = DateTime.Now; dish.LastModifiedDateTime = DateTime.Now; _context.Add(dish); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["DishTypeId"] = new SelectList(_context.DishType, "DishTypeId", "DishType1", dish.DishTypeId); ViewData["UnitOfMeasureId"] = new SelectList(_context.UnitOfMeasure, "UnitOfMeasureId", "UnitOfMeasure1", dish.UnitOfMeasureId); return(View(dish)); }
public async Task <IActionResult> Create([Bind("CourierId,Name,Surname,Phone,CourierTypeId,CreatedDateTime,LastModifiedDateTime")] Courier courier) { if (ModelState.IsValid) { courier.CreatedDateTime = DateTime.Now; courier.LastModifiedDateTime = DateTime.Now; _context.Add(courier); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["CourierTypeId"] = new SelectList(_context.CourierType, "CourierTypeId", "Type", courier.CourierTypeId); return(View(courier)); }
public async Task <IActionResult> Create([Bind("OrderId,CustomerId,TotalAmt,Description,CreatedDateTime,LastModifiedDateTime")] Order order) { if (ModelState.IsValid) { order.CreatedDateTime = DateTime.Now; order.LastModifiedDateTime = DateTime.Now; order.Status = OrderStatus.Created; _context.Add(order); await _context.SaveChangesAsync(); return(RedirectToRoute(new { controller = "Orders", action = "Details", id = order.OrderId })); //return RedirectToAction(nameof(Index)); } ViewData["CustomerId"] = new SelectList(_context.Customer, "CustomerId", "Name", order.CustomerId); return(View(order)); }
public async Task <IActionResult> Create([Bind("OrderLineId,OrderId,RestaurantDishRelationId,Quantity,CreatedDateTime,LastModifiedDateTime")] OrderLine orderLine) { if (ModelState.IsValid) { orderLine.CreatedDateTime = DateTime.Now; orderLine.LastModifiedDateTime = DateTime.Now; var order = _context.Order.Find(orderLine.OrderId); order.TotalAmt = order.OrderLine.Sum(o => o.Quantity * o.RestaurantDishRelation.Price); _context.Update(order); _context.Add(orderLine); await _context.SaveChangesAsync(); return(RedirectToRoute(new { controller = "Orders", action = "Details", id = orderLine.OrderId })); //return RedirectToAction(nameof(Index)); } ViewData["OrderId"] = new SelectList(_context.Order, "OrderId", "OrderId", orderLine.OrderId); ViewData["RestaurantDishRelationId"] = new SelectList(_context.RestaurantDishRelation, "RestaurantDishRelationId", "RestaurantDishRelationId", orderLine.RestaurantDishRelationId); return(RedirectToRoute(new { controller = "Details", action = "Order", id = orderLine.OrderId })); }