/* public ActionResult SetSuppliers(int id) * { * var employee = _userManager.GetUsersInRoleAsync("EMployee").Result; * * } */ // GET: productdetails/Details/5 public ActionResult Details(int id) { if (!_repos.isExist(id)) { return(NotFound()); } var typesofproducts = _repos.FindById(id); var Mappingtolist = _mapper.Map <ProductDetailsViewModel>(typesofproducts); return(View(Mappingtolist)); }
public ActionResult Create(SalesItemViewModel model) { // var Customers = _custumRepo.FindAll(); try { //customer making the purchase and getting the user who is sign in. // getting if the person is inside of the data base // var customer = _custumRepo.GetCustomerByID(customerIdentity.Id); //var customerIdentity = _userManager.GetUserAsync(User).Result; var Customers = _custumRepo.FindAll(); var customername = Customers.Select(q => new SelectListItem { Text = q.CustomerNAme, Value = q.CustomerId.ToString() }); var Products = _ProdRepo.FindAll(); var productItems = Products.Select(q => new SelectListItem { Text = $"{q.ProductName} - ${q.ProductPrice}", Value = q.ProductId.ToString() }); model.Customers = customername; model.ProductDetails = productItems; var product = _ProdRepo.FindById(model.ProductId); var totalcost = model.Total; if (product.Quantity > model.Quantity) { // ModelState.AddModelError("", "Please place quantity value"); // totalcost = salesonitem.ProductPrice * salesonitem.Quantity; totalcost = product.ProductPrice * model.Quantity; } else if (model.Quantity <= 0) { ModelState.AddModelError("", "please enter a value for the quantity"); return(View(model)); } model.Total = totalcost; var calculation = new SalesItemViewModel {//objects CustomerId = model.CustomerId, CustomerNAme = model.CustomerNAme, Customers = model.Customers, ProductDetails = model.ProductDetails, ProductName = model.ProductName, ProductPrice = model.ProductPrice, Quantity = model.Quantity, SalesItemId = model.SalesItemId, Total = model.Total, ProductId = model.ProductId }; var salesproduct = _mapper.Map <SalesItem> (calculation); var issuccessful = _Salesrepos.Create(salesproduct); if (!issuccessful)//if the insertion failed { ModelState.AddModelError("", "Something Went wrong submitting your record......"); return(View(model)); } return(RedirectToAction(nameof(Index))); } catch (Exception ex) { ModelState.AddModelError("", "Something Went wrong submitting your record......"); return(View(model)); } }