public ActionResult Destroy([DataSourceRequest] DataSourceRequest request, LaptopViewModel laptop) { if (laptop != null && ModelState.IsValid) { var laptopToDelete = this.Data.Laptops.GetById(laptop.Id); if (laptopToDelete == null) { ModelState.AddModelError( "alert", "An unexpected error has occurred. The laptop you want to delete was not found..."); return(Json(ModelState.ToDataSourceResult())); } foreach (var vote in laptopToDelete.Votes.ToList()) { this.Data.Votes.Delete(vote); } foreach (var comment in laptopToDelete.Comments.ToList()) { this.Data.Comments.Delete(comment); } this.Data.Laptops.Delete(laptopToDelete); this.Data.SaveChanges(); } return(Json(new object())); }
public LaptopView() { InitializeComponent(); context = new LaptopViewModel(); BindingContext = context; this.Title = "App Javeriana"; }
public ActionResult Update([DataSourceRequest] DataSourceRequest request, LaptopViewModel laptop) { if (laptop != null && ModelState.IsValid) { var laptopToUpdate = this.Data.Laptops.GetById(laptop.Id); if (laptopToUpdate == null) { ModelState.AddModelError( "alert", "An unexpected error has occurred. The laptop you want to update was not found..."); return(Json(ModelState.ToDataSourceResult())); } laptopToUpdate.Model = laptop.Model.Trim(); laptopToUpdate.HardDiskCapacity = laptop.HardDiskCapacity; laptopToUpdate.ImageUrl = laptop.ImageUrl; laptopToUpdate.ManufacturerId = laptop.ManufacturerId; laptopToUpdate.MonitorSize = laptop.MonitorSize; laptopToUpdate.Price = laptop.Price; laptopToUpdate.RamCapacity = laptop.RamCapacity; this.Data.SaveChanges(); return(Json(new object())); } return(Json(ModelState.ToDataSourceResult())); }
public ActionResult Create([DataSourceRequest] DataSourceRequest request, LaptopViewModel laptop) { var results = new List <LaptopViewModel>(); if (laptop != null && ModelState.IsValid) { var newLaptop = new Laptop() { Model = laptop.Model.Trim(), HardDiskCapacity = laptop.HardDiskCapacity, ImageUrl = laptop.ImageUrl, ManufacturerId = laptop.ManufacturerId, MonitorSize = laptop.MonitorSize, Price = laptop.Price, RamCapacity = laptop.RamCapacity }; this.Data.Laptops.Add(newLaptop); this.Data.SaveChanges(); results.Add(laptop); } return(Json(results.ToDataSourceResult(request))); }
public ActionResult List(int categoryid) { List <Laptop> laptops = eCart.Laptops.Where(c => c.LapCategoryId == categoryid).ToList(); LaptopViewModel laptopView = new LaptopViewModel(); laptopView.Laptops = laptops; return(View(laptopView)); }
public ActionResult NavBar() { List <LaptopCategory> categories = eCart.LaptopCategories.ToList(); LaptopViewModel laptopViewModel = new LaptopViewModel(); laptopViewModel.LaptopCategories = categories; return(PartialView(laptopViewModel)); }
public ActionResult UpdateLaptopCust(LaptopViewModel laptopVM) { var mapper = new MapperConfiguration(cfg => cfg.CreateMap <LaptopViewModel, LaptopDTO>()).CreateMapper(); LaptopDTO laptopDto = mapper.Map <LaptopViewModel, LaptopDTO>(laptopVM); service.UpdateLaptop(laptopDto); return(View("Index")); }
public JsonResult Delete(LaptopViewModel laptopModel) { try { _genericService.Delete(laptopModel.ID); return(Json(new { Result = "OK" })); } catch (Exception ex) { return(Json(new { Result = "ERROR", Message = ex.Message })); } }
public JsonResult Edit(LaptopViewModel laptopModel) { try { _genericService.Update(_mapper.Map <LaptopViewModel, LaptopDTO>(laptopModel)); return(Json(new { Result = "OK", Record = laptopModel })); } catch (Exception ex) { return(Json(new { Result = "ERROR", Message = ex.Message })); } }
public JsonResult Create(LaptopViewModel laptopModel) { try { var id = _genericService.Save(_mapper.Map <LaptopViewModel, LaptopDTO>(laptopModel)); laptopModel.ID = id; return(Json(new { Result = "OK", Record = laptopModel })); } catch (Exception ex) { return(Json(new { Result = "ERROR", Message = ex.Message })); } }
public ActionResult GetLaptop(int laptopIdDto) { LaptopDTO laptopDTO = service.GetLaptop(laptopIdDto); var mapper = new MapperConfiguration(cfg => cfg.CreateMap <LaptopDTO, LaptopViewModel>()).CreateMapper(); LaptopViewModel laptopVM = mapper.Map <LaptopDTO, LaptopViewModel>(laptopDTO); var mapper1 = new MapperConfiguration(cfg => cfg.CreateMap <ImageDTO, Image>()).CreateMapper(); IEnumerable <Image> images = mapper1.Map <IEnumerable <ImageDTO>, IEnumerable <Image> >(service.GetImages()); laptopVM.Images.AddRange(images.Where(i => i.ProductId == laptopVM.Id)); var mapper2 = new MapperConfiguration(cfg => cfg.CreateMap <OrderSellerDTO, OrderSeller>()).CreateMapper(); OrderSeller seller = mapper2.Map <OrderSellerDTO, OrderSeller>(service.GetOrderSeller(laptopVM.OrderSellerId)); laptopVM.OrderSeller = seller; return(View(laptopVM)); }
public ActionResult Add(LaptopViewModel viewmodel, string modelName) { ViewBag.LM = context.Stocks.ToList().Where(x => x.category == "Laptop"); List <Stock> slist = new List <Stock>(context.Stocks.ToList().Where(x => x.category == "Laptop")); List <SelectListItem> li = new List <SelectListItem>(); foreach (var item in slist) { var man = li.Find(x => x.Value == item.manufacturer); if (man == null) { li.Add(new SelectListItem { Text = item.manufacturer, Value = item.manufacturer }); } } viewmodel.modelName = modelName; ViewBag.LL = li; ViewBag.LM = context.Stocks.ToList().Where(x => x.category == "Laptop"); if (ModelState.IsValid) { AssetLogic al = new AssetLogic(); try { Stock stock = context.Stocks.FirstOrDefault(m => m.model.Equals(viewmodel.modelName) && m.manufacturer.Equals(viewmodel.manufacturer) && m.category.Equals("Laptop")); if (stock != null && stock.quantity != 0) { var asset = new Asset { manufacturer = viewmodel.manufacturer, serialNumber = viewmodel.serialNumber, dateadded = viewmodel.dateAdded, warranty = viewmodel.warranty + " Months", costprice = viewmodel.costprice, InvoiceNumber = viewmodel.InvoiceNumber, depreciationcost = al.depreciationCost(viewmodel.dateAdded, viewmodel.costprice) }; var laptop = new Laptop { serialNumber = viewmodel.serialNumber, manufacturer = viewmodel.manufacturer, modelName = viewmodel.modelName, warranty = viewmodel.warranty + " Months", dateAdded = viewmodel.dateAdded, HDD = viewmodel.HDD, OS = viewmodel.OS, RAM = viewmodel.RAM, screenSize = viewmodel.screenSize, InvoiceNumber = viewmodel.InvoiceNumber, processor = viewmodel.processor }; stock.quantity = stock.quantity - 1; repository.Insert(asset, laptop); repository.Save(); context.SaveChanges(); TempData["Success"] = "Asset has been added!"; } else { ViewBag.Message = "Asset model not available in stock. Update your stock."; } } catch (Exception e) { ViewBag.Message = "Asset not added. Error: " + e.Message; } } ModelState.Clear(); return(View(viewmodel)); }
public ActionResult CreateOrderCustomer(OrderCustomerViewModel customerVM) { if (ModelState.IsValid) { var mapper = new MapperConfiguration(cfg => cfg.CreateMap <OrderCustomerViewModel, OrderCustomerDTO>()).CreateMapper(); OrderCustomerDTO customerDto = mapper.Map <OrderCustomerViewModel, OrderCustomerDTO>(customerVM); service.CreateOrderCustomer(customerDto); string category = service.GetProduct(customerVM.ProdId); if (category == "Phone") { PhoneDTO phoneDTO = service.GetPhone(customerVM.ProdId); if (phoneDTO.QtyEnd == 0) { return(View("ProductEnded")); } phoneDTO.QtyEnd--; phoneDTO.PriceNow = Price(phoneDTO.PriceStart, phoneDTO.PriceEnd, phoneDTO.QtyEnd); var mapper1 = new MapperConfiguration(cfg => cfg.CreateMap <PhoneDTO, PhoneViewModel>()).CreateMapper(); PhoneViewModel phoneVM = mapper1.Map <PhoneDTO, PhoneViewModel>(phoneDTO); return(View("ThanksPagePhone", phoneVM)); } if (category == "TV") { TVDTO tvDTO = service.GetTV(customerVM.ProdId); if (tvDTO.QtyEnd == 0) { return(View("ProductEnded")); } tvDTO.QtyEnd--; tvDTO.PriceNow = Price(tvDTO.PriceStart, tvDTO.PriceEnd, tvDTO.QtyEnd); var mapper1 = new MapperConfiguration(cfg => cfg.CreateMap <TVDTO, TVViewModel>()).CreateMapper(); TVViewModel tvVM = mapper1.Map <TVDTO, TVViewModel>(tvDTO); return(View("ThanksPageTV", tvVM)); } if (category == "Laptop") { LaptopDTO laptopDTO = service.GetLaptop(customerVM.ProdId); if (laptopDTO.QtyEnd == 0) { return(View("ProductEnded")); } laptopDTO.QtyEnd--; laptopDTO.PriceNow = Price(laptopDTO.PriceStart, laptopDTO.PriceEnd, laptopDTO.QtyEnd); var mapper1 = new MapperConfiguration(cfg => cfg.CreateMap <LaptopDTO, LaptopViewModel>()).CreateMapper(); LaptopViewModel laptopVM = mapper1.Map <LaptopDTO, LaptopViewModel>(laptopDTO); return(View("ThanksPageLaptop", laptopVM)); } return(View("ThanksPagePhone")); } return(View("ThanksPagePhone")); }