public ActionResult CreateGPU([Bind(Include = "ProductId,TypeID,Manufacturer,Name,Price,VRAM,Image,Description")] GPUViewModel 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.GPU, 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 gpu = new GPU { ProductId = pr.ProductId, VRAM = product.VRAM }; db.GPU.Add(gpu); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(product)); }
public ActionResult Create(GPUViewModel gpu) { if (ModelState.IsValid) { var gpudto = Mapper.Map <GPUViewModel, GPUdto>(gpu); Service.SaveGPU(gpudto); return(RedirectToAction("Index")); } return(View(gpu)); }
public JsonResult Delete(GPUViewModel gpuModel) { try { _genericService.Delete(gpuModel.ID); return(Json(new { Result = "OK" })); } catch (Exception ex) { return(Json(new { Result = "ERROR", Message = ex.Message })); } }
public JsonResult Edit(GPUViewModel gpuModel) { try { _genericService.Update(_mapper.Map <GPUViewModel, GPUDTO>(gpuModel)); return(Json(new { Result = "OK", Record = gpuModel })); } catch (Exception ex) { return(Json(new { Result = "ERROR", Message = ex.Message })); } }
public JsonResult Create(GPUViewModel gpuModel) { try { var id = _genericService.Save(_mapper.Map <GPUViewModel, GPUDTO>(gpuModel)); gpuModel.ID = id; return(Json(new { Result = "OK", Record = gpuModel })); } catch (Exception ex) { return(Json(new { Result = "ERROR", Message = ex.Message })); } }
public ActionResult Edit(GPUViewModel gpu) { if (ModelState.IsValid) { var gpudto = Mapper.Map <GPUViewModel, GPUdto>(gpu); Service.EditGPU(gpudto); TempData["message"] = string.Format("{0} has been saved", gpu.Name); return(RedirectToAction("Index")); } else { return(View(gpu)); } }
public RedirectToRouteResult GPUAddToCompare( Comparison <GPUViewModel> comparison, System.Guid ProductGuid, string returnUrl) { GPUdto gpudto = Service.FindGPUByID(ProductGuid); GPUViewModel gpu = Mapper.Map <GPUdto, GPUViewModel>(gpudto); if (gpu != null) { comparison.AddItem(gpu); } return(RedirectToAction("GPUCompare", new { returnUrl })); }
public ActionResult GPUDetails(int?id) { GPUViewModel gpu = new GPUViewModel { 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, VRAM = db.GPU.Find(id).VRAM, Image = db.Product.Find(id).Image, Description = db.Product.Find(id).Description }; return(View(gpu)); }
//[ValidateAntiForgeryToken] public IActionResult Create(GPUViewModel model) { var gpu = new GPU() { Name = model.Name }; var result = _gpuService.CreateGPU(gpu); if (result.Succedeed) { return(Json(gpu)); } return(Json(result)); }
public void Create_AddGPU_ReturneRightModel() { //Arrange Guid guid1 = Guid.NewGuid(); string GPU1 = "GPU1"; GPUViewModel GPU = new GPUViewModel { ProductGuid = guid1, Name = GPU1 }; //Service.Setup(x => x.GetGPUs()).Returns(GPU); GPUsController controller = new GPUsController(Service.Object, Mapper); //Act var result = controller.Create(GPU) as ViewResult; //Assert Service.Verify(x => x.SaveGPU(It.IsAny <GPUdto>())); }
public void Delete_DeleteGPU_ServiceMethodWereCalled() { //Arrange Guid guid1 = Guid.NewGuid(); string GPU1 = "GPU1"; GPUViewModel GPU = new GPUViewModel { ProductGuid = guid1, Name = GPU1 }; //Service.Setup(x => x.GetGPUs()).Returns(GPU); GPUsController controller = new GPUsController(Service.Object, Mapper); //Act var result = controller.Delete(guid1) as ViewResult; //Assert Service.Verify(x => x.DeleteGPU(guid1)); }
public void Edit_UpdateGPU_ServiceMethodWereCalled() { //Arrange Guid guid1 = Guid.NewGuid(); string GPU1 = "GPU1"; GPUViewModel GPU = new GPUViewModel { ProductGuid = guid1, Name = GPU1 }; //Service.Setup(x=>x.EditGPU()) GPUsController controller = new GPUsController(Service.Object, Mapper); //Act var result = controller.Edit(GPU) as ViewResult; //Assert Service.Verify(x => x.EditGPU(It.IsAny <GPUdto>())); }
//[ValidateAntiForgeryToken] public ActionResult Edit(GPUViewModel model) { var gpu = _gpuService.GetGPU(model.Id); if (gpu == null) { return(NotFound()); } gpu.Name = model.Name; var result = _gpuService.UpdateGPU(gpu); if (result.Succedeed) { return(Json(gpu)); } return(Json(result)); }
public ActionResult GPUEdit([Bind(Include = "ProductId,TypeID,Manufacturer,Name,Price,VRAM,Description,Image")] GPUViewModel 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 }; GPU newG = new GPU { ProductId = product.ProductId, VRAM = product.VRAM }; db.Entry(newP).State = EntityState.Modified; db.SaveChanges(); db.Entry(newG).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(product)); }