public ActionResult CreateRAM([Bind(Include = "ProductId,TypeID,Manufacturer,Name,Price,Speed,Capacity,Description")] RAMViewModel product, HttpPostedFileBase uploadImage) { if (product.Price < 1) { ModelState.AddModelError(string.Empty, "Цена не может быть негативной"); } if (ModelState.IsValid) { byte[] imageData = null; var pr = new Product { Manufacturer = product.Manufacturer, Name = product.Name, Price = product.Price, TypeID = ProductType.RAM, Description = product.Description }; if (uploadImage != null) { using (var binaryReader = new BinaryReader(uploadImage.InputStream)) { imageData = binaryReader.ReadBytes(uploadImage.ContentLength); pr.Image = imageData; } } db.Product.Add(pr); db.SaveChanges(); var ram = new RAM { ProductId = pr.ProductId, Speed = product.Speed, Capacity = product.Capacity }; db.RAM.Add(ram); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(product)); }
public JsonResult Delete(RAMViewModel ramModel) { try { _genericService.Delete(ramModel.ID); return(Json(new { Result = "OK" })); } catch (Exception ex) { return(Json(new { Result = "ERROR", Message = ex.Message })); } }
public JsonResult Edit(RAMViewModel ramModel) { try { _genericService.Update(_mapper.Map <RAMViewModel, RAMDTO>(ramModel)); return(Json(new { Result = "OK", Record = ramModel })); } catch (Exception ex) { return(Json(new { Result = "ERROR", Message = ex.Message })); } }
public JavaScriptResult Create(RAMViewModel RAMvm) { try { _ramService.Add(Mapper.Map <RAM>(RAMvm)); return(JavaScript($"ShowResult('{"Data saved successfully."}','{"success"}','{"redirect"}','{"/APanel/RAM"}')")); } catch (Exception ex) { return(JavaScript($"ShowResult('{ex.Message}','failure')")); } }
public JsonResult Create(RAMViewModel ramModel) { try { var id = _genericService.Save(_mapper.Map <RAMViewModel, RAMDTO>(ramModel)); ramModel.ID = id; return(Json(new { Result = "OK", Record = ramModel })); } catch (Exception ex) { return(Json(new { Result = "ERROR", Message = ex.Message })); } }
public ActionResult RAMDetails(int?id) { RAMViewModel ram = new RAMViewModel { ProductId = (int)id, TypeID = db.Product.Find(id).TypeID, Manufacturer = db.Product.Find(id).Manufacturer, Name = db.Product.Find(id).Name, Price = db.Product.Find(id).Price, Speed = db.RAM.Find(id).Speed, Capacity = db.RAM.Find(id).Capacity, Image = db.Product.Find(id).Image, Description = db.Product.Find(id).Description }; return(View(ram)); }
public ActionResult RAMEdit([Bind(Include = "ProductId,TypeID,Manufacturer,Name,Price,Speed,Capacity,Description,Image")] RAMViewModel product, HttpPostedFileBase uploadImage) { if (product.Price < 1) { ModelState.AddModelError(string.Empty, "Цена не может быть негативной"); } if (ModelState.IsValid) { byte[] imageData = null; if (uploadImage != null) { using (var binaryReader = new BinaryReader(uploadImage.InputStream)) { imageData = binaryReader.ReadBytes(uploadImage.ContentLength); product.Image = imageData; } } Product newP = new Product { ProductId = product.ProductId, Manufacturer = product.Manufacturer, Name = product.Name, Price = product.Price, TypeID = product.TypeID, Image = product.Image, Description = product.Description }; RAM newR = new RAM { ProductId = product.ProductId, Capacity = product.Capacity, Speed = product.Speed }; db.Entry(newP).State = EntityState.Modified; db.SaveChanges(); db.Entry(newR).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(product)); }
public async Task <IActionResult> LoadRAMs() { ViewData["HwType"] = "RAM"; string moboID = HttpContext.Session.GetString(SessionKeyMOBO); MOBO mobo = null; if (!String.IsNullOrEmpty(moboID)) { mobo = await _context.MOBOes.SingleOrDefaultAsync(m => m.Id == Int32.Parse(moboID)); } List <RAM> ramList = await _context.RAMs.AsNoTracking().ToListAsync(); List <RAMViewModel> ramListValidated = new List <RAMViewModel>(); foreach (var item in ramList) { RAMViewModel ramValidated = new RAMViewModel { RAM = item, Ram_type_ok = true }; if (mobo != null) { if (!item.Ram_type.Equals(mobo.Ram_type)) { ramValidated.Ram_type_ok = false; } } ramListValidated.Add(ramValidated); } return(View("RAMs", ramListValidated)); }