public async Task <IActionResult> CreatePercentage(PercentageModelView vaucher) { if (ModelState.IsValid) { string code = await CreatePerCodeAsync(vaucher.Percentage); Vauchers perVaucher = new Vauchers(); perVaucher.Code = code; perVaucher.Percentage = vaucher.Percentage; Employees emp = await GetEmployeeByUserIdAsync(); perVaucher.CreatedBy = emp.Id; perVaucher.CustomerId = vaucher.CustomerId; perVaucher.IsUsed = false; _context.Add(perVaucher); await _context.SaveChangesAsync(); TempData["Styling"] = "alert rounded shadow alert-success"; TempData["Msg"] = "Voucher " + perVaucher.Code + " added succesfully!"; return(RedirectToAction(nameof(Index))); } TempData["Styling"] = "alert rounded shadow alert-danger"; TempData["Msg"] = "Percentage must be > 0 and < 50!"; return(RedirectToAction("index")); }
public IActionResult Return(int?OrderId, int?ProductId, int?Quantity, string?Reason) { if (OrderId == null || ProductId == null) { return(NotFound()); } Orders order = _context.Orders.FirstOrDefault(m => m.Id == OrderId); OrderDetails details = _context.OrderDetails.Where(m => m.OrderId == OrderId).Include(o => o.Product).FirstOrDefault(o => o.ProductId == ProductId); if (Quantity == 0 || Quantity == null || Reason == null || Quantity > details.Quantity) { TempData["DangerMsg"] = "Quantity must be greater than 0 but lower then total ordered quantity and reason is required"; TempData["Styling"] = "alert rounded shadow alert-danger"; return(RedirectToAction("Details", new { id = OrderId })); } Returns returnn = new Returns { CustomerId = (int)order.CustomerId, OrderId = order.Id, ReturnStatusId = 1, TotalPrice = 0 }; _context.Add(returnn); _context.SaveChanges(); ReturnDetails returnDetails = new ReturnDetails { ReturnId = returnn.Id, ProductId = (int)ProductId, Quantity = (int)Quantity, Reason = (string)Reason }; returnn.TotalPrice = details.Price * returnDetails.Quantity; try { _context.Update(returnn); _context.Add(returnDetails); _context.SaveChanges(); TempData["SuccessMsg"] = "Return request was sent"; TempData["Styling"] = "alert rounded shadow alert-success"; } catch { TempData["DangerMsg"] = "Something went wrong, try again later!"; TempData["Styling"] = "alert rounded shadow alert-danger"; return(RedirectToAction("Details", new { id = OrderId })); } return(RedirectToAction("Details", new { id = OrderId })); }
public async Task <IActionResult> Create([Bind("Id,Name")] Categories categories) { if (ModelState.IsValid) { _context.Add(categories); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(categories)); }
public async Task <IActionResult> Create([Bind("Id,Details")] Promotions promotions) { if (ModelState.IsValid) { _context.Add(promotions); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(promotions)); }
public async Task <IActionResult> Create([Bind("Id,Status")] OrderStatus orderStatus) { if (ModelState.IsValid) { _context.Add(orderStatus); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(orderStatus)); }
public async Task <IActionResult> Create([Bind("Id,UserId,ContactPerson,PhoneNumber,Mail,Company,Cui,RegistrationNumber,Adress,CityId,Bank,Iban,TypeId")] Customers customers) { var userId = getUserID(); customers.UserId = userId; ModelState.Remove("UserId"); if (ModelState.IsValid) { var user = await userManager.FindByIdAsync(userId); var result = await userManager.AddToRoleAsync(user, "User"); if (!result.Succeeded) { foreach (IdentityError error in result.Errors) { ModelState.AddModelError("", error.Description); } } } customers.IsAccepted = false; if (ModelState.IsValid) { _context.Add(customers); await _context.SaveChangesAsync(); Customers customer = await GetCustomerByUserIdAsync(); Carts cart = new Carts(); cart.CutomerId = customer.Id; _context.Add(cart); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["CityId"] = new SelectList(_context.Cities, "Id", "Name", customers.CityId); ViewData["TypeId"] = new SelectList(_context.Type, "Id", "Name", customers.TypeId); return(View(customers)); }
public async Task <IActionResult> Create([Bind("Id,FullName,email,Adress,CityId,JobId,Salary")] Employees employees) { var user = await userManager.FindByNameAsync(employees.email); ViewData["CityId"] = new SelectList(_context.Cities, "Id", "Name"); ViewData["JobId"] = new SelectList(roleManager.Roles); if (user == null) { ViewBag.Class = "alert alert-danger"; ViewBag.ErrorMsg = " This email dose not corespond to an user account."; return(View()); } else { employees.UserId = user.Id; if (_context.Employees.FirstOrDefault(e => e.email == employees.email) != null) { ViewBag.Class = "alert alert-danger"; ViewBag.ErrorMsg = " This email is already linked to an employee acount."; return(View()); } else { if (ModelState.IsValid) { try { var result = await userManager.AddToRoleAsync(user, employees.JobId); } catch (Exception) { ViewBag.Class = "alert alert-danger"; ViewBag.ErrorMsg = "Role not valid"; View(employees); } _context.Add(employees); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(employees)); } } }
public async Task <IActionResult> Create(ProductsViewModel products) { if (ModelState.IsValid) { string uniquFileName = null; if (products.photo != null) { string uploadsFolder = Path.Combine(hostingEnviroment.WebRootPath, "images"); uniquFileName = Guid.NewGuid().ToString() + "_" + products.Name + "_" + products.photo.FileName; string filePath = Path.Combine(uploadsFolder, uniquFileName); products.photo.CopyTo(new FileStream(filePath, FileMode.Create)); } Products product = new Products { ProductCode = products.ProductCode, Name = products.Name, Weight = products.Weight, UmId = products.UmId, InitialPrice = products.InitialPrice, Discount = products.Discount, FinalPrice = products.FinalPrice, Quantity = products.Quantity, Details = products.Details, UnitsPerBox = products.UnitsPerBox, CateogryId = products.CateogryId, ManufacturerId = products.ManufacturerId, Image = uniquFileName }; product.FinalPrice = product.InitialPrice - product.Discount; _context.Add(product); await _context.SaveChangesAsync(); return(RedirectToAction("details", new { id = product.Id })); } ViewData["CateogryId"] = new SelectList(_context.Categories, "Id", "Name", products.CateogryId); ViewData["ManufacturerId"] = new SelectList(_context.Manufacturers, "Id", "Name", products.ManufacturerId); ViewData["UmId"] = new SelectList(_context.Um, "Id", "Name", products.UmId); return(View(products)); }
public async Task <IActionResult> CreateDeliver(int?id, IEnumerable <CreateDeliverViewModel> deliverRecived) { if (id == null) { return(NotFound()); } var order = await _context.Orders.Include(o => o.Customer).FirstOrDefaultAsync(o => o.Id == id); if (order == null || order.OrderStatusId != 9) { return(NotFound()); } var orderDetails = _context.OrderDetails.Where(o => o.OrderId == order.Id).Include(o => o.Product); DateTime currentDate = DateTime.Now.Date; bool errorFound = false; int carid = 0; DateTime?shippingDate = null; foreach (var item in deliverRecived) { if (item.ExpDate < currentDate) { errorFound = true; ViewBag.error = "Date must be from future"; } if (item.CarId != null) { carid = (int)item.CarId; } if (item.ShippingDate != null) { shippingDate = item.ShippingDate; } OrderDetails ord = await _context.OrderDetails.FirstOrDefaultAsync(o => o.OrderId == order.Id && o.ProductId == item.productId); ord.ExpDate = item.ExpDate; try { _context.Update(ord); await _context.SaveChangesAsync(); } catch { return(NotFound()); } } if (carid == 0) { errorFound = true; ViewBag.carError = "Select a car"; } if (shippingDate == null || shippingDate <= currentDate) { errorFound = true; ViewBag.shippingEroor = "Shipping date must be from future"; } if (errorFound) { IList <OrderDetails> orderDetailsList = await orderDetails.ToListAsync(); IList <CreateDeliverViewModel> deliver = new List <CreateDeliverViewModel>(); for (int i = 0; i < orderDetailsList.Count; i++) { CreateDeliverViewModel temp = new CreateDeliverViewModel(); temp.productId = orderDetailsList[i].ProductId; temp.productName = orderDetailsList[i].Product.Name; temp.OrderId = orderDetailsList[i].OrderId; deliver.Add(temp); } ViewBag.Cars = new SelectList(_context.Cars, "Id", "RegistrationPlate"); ViewBag.Order = order.Id; ViewBag.customer = order.Customer.Company; return(View(deliver)); } Delivers newDeliver = new Delivers(); newDeliver.OrderId = order.Id; var employee = await GetEmployeeByUserIdAsync(); newDeliver.EmployeeId = employee.Id; newDeliver.CustomerId = (int)order.CustomerId; newDeliver.CarId = carid; newDeliver.StatusDeliverId = 1; _context.Add(newDeliver); await _context.SaveChangesAsync(); foreach (var item in orderDetails) { DeliverDetails temp = new DeliverDetails(); temp.ProductId = item.ProductId; temp.Quantity = item.Quantity; temp.DeliverId = newDeliver.Id; _context.Add(temp); } order.ShippingDate = shippingDate; order.OrderStatusId = 14; try { _context.Update(order); await _context.SaveChangesAsync(); } catch { return(NotFound()); } return(RedirectToAction("index", "Delivers")); }
public async Task <IActionResult> CheckOut() { var cart = await GetCurrentUserCartAsync(); var customer = await GetCustomerByUserIdAsync(); await CalculaTetoatalAsync(); var cartDetails = _context.CartDetails .Where(c => c.CartId == cart.Id) .Include(c => c.Product); foreach (var item in cartDetails) { if (item.Quantity > item.Product.Quantity) { @TempData["CartMessage"] = "Product " + item.Product.Name + " stock was exceeded"; return(RedirectToAction("index")); } } if (cartDetails.Count() < 1) { @TempData["CartMessage"] = "Cart is empty"; return(RedirectToAction("index")); } if (customer.Credit < ViewBag.total) { @TempData["CartMessage"] = "Credit exceeded"; return(RedirectToAction("index")); } Orders order = new Orders(); order.OrderStatusId = 8; order.CustomerId = customer.Id; DateTime date = DateTime.Now; order.Date = date; order.isPaid = false; order.DiscountVal = ViewBag.discountVal + ViewBag.discPackage; if (order.DiscountVal == 0) { order.DiscountVal = null; } order.TotalPrice = ViewBag.total; _context.Add(order); await _context.SaveChangesAsync(); var id = order.Id; foreach (var item in cartDetails) { OrderDetails orderDetails = new OrderDetails(); Products product = await _context.Products.FirstOrDefaultAsync(p => p.Id == item.ProductId); product.Quantity = product.Quantity - item.Quantity; orderDetails.OrderId = order.Id; orderDetails.ProductId = item.ProductId; orderDetails.Quantity = item.Quantity; if (ViewBag.discountPer > 0) { orderDetails.DiscountPer = ViewBag.discountPer; } orderDetails.Price = item.Product.FinalPrice - ViewBag.discountPer * item.Product.FinalPrice / 100; try { _context.Update(product); } catch { return(NotFound()); } _context.Add(orderDetails); _context.Remove(item); } await _context.SaveChangesAsync(); cart.DiscountPer = null; cart.DiscountVal = null; customer.Credit = customer.Credit - ViewBag.total; try { _context.Update(cart); await _context.SaveChangesAsync(); } catch { return(NotFound()); } return(RedirectToAction("details", "Orders", new { Id = id })); }