public async Task <IActionResult> EditSubmit(CategoryEditVm model, IFormFile Image) { var upCat = this.dbContext.Categories .FirstOrDefault(c => c.Id == model.Id); if (upCat == null) { return(NotFound()); } if (ModelState.IsValid) { if (Image != null) { string name = Image.FileName; string path = $"/files/{name}"; string serverPath = $"{this.environment.WebRootPath}{path}"; FileStream fs = new FileStream(serverPath, FileMode.Create, FileAccess.Write); await Image.CopyToAsync(fs); fs.Close(); upCat.Image = path; } } upCat.Name = model.Name; this.dbContext.Categories.Update(upCat); this.dbContext.SaveChanges(); return(RedirectToAction("Index")); }
public IActionResult Edit(int?id) { if (HttpContext.Session.GetInt32("LoginLevel") != 2) { ViewBag.checkLogin = 0; return(View("../Home/AddCart")); } if (id == null) { return(NotFound()); } var cate = _service.GetCate(id.Value); if (cate == null) { return(NotFound()); } CategoryEditVm CategoryEditVM = new CategoryEditVm() { Id = cate.ID, Name = cate.Name, Description = cate.Description, Status = cate.Status, ExistPhotoPath = cate.PhotoPath }; var x = _categoryService.GetList(); ViewBag.StatusList = x.StatusList; return(View(CategoryEditVM)); }
public void UpdateCategory(CategoryEditVm entity) { var sEntity = _rep.Categories.GetById(entity.Id); sEntity.Name = entity.Name; sEntity.ParrentCategory = _rep.Categories.GetById(Guid.Parse(entity.ParrentCategory.SelectedItem)); _rep.Categories.Update(sEntity); }
public IActionResult Edit(CategoryEditVm viewmodel) { if (ModelState.IsValid) { using (var ctx = new ApplicationContext()) { var category = ctx.PostCategories.Find(viewmodel.Id); category.Title = viewmodel.Title; ctx.SaveChanges(); } } return(RedirectToAction("List", "CategoryManagment")); }
public IActionResult Edit(int Id) { using (var ctx = new ApplicationContext()) { var category = ctx.PostCategories.Find(Id); CategoryEditVm model = new CategoryEditVm { Id = category.Id, Title = category.Title }; return(View(model)); } }
public IActionResult Edit(CategoryEditVm model) { if (HttpContext.Session.GetInt32("LoginLevel") != 2) { ViewBag.checkLogin = 0; return(View("../Home/AddCart")); } if (ModelState.IsValid) { var categories = _service.GetAll(); foreach (CategoryDto item in categories) { if (item.Name.ToLower().Equals(model.Name.ToLower()) && item.ID != model.Id) { ViewBag.CategoryNameEditDuplicateErrorMessage = "Error"; var x = _categoryService.GetList(); ViewBag.StatusList = x.StatusList; return(View(model)); } } CategoryDto categoryDto = _service.GetCate(model.Id); SaveCategoryDto saveCategoryDto = _mapper.Map <CategoryDto, SaveCategoryDto>(categoryDto); saveCategoryDto.Name = model.Name; saveCategoryDto.Description = model.Description; saveCategoryDto.Status = model.Status; saveCategoryDto.PhotoPath = model.ExistPhotoPath; if (model.Photo != null) { if (model.ExistPhotoPath != null) { string filePath = Path.Combine(_hostingEnvironment.WebRootPath, "images", model.ExistPhotoPath); System.IO.File.Delete(filePath); } saveCategoryDto.PhotoPath = ProcessUploadedFile(model); } _service.Update(saveCategoryDto); return(View("Detail", _service.GetCate(saveCategoryDto.ID))); } return(View()); }
public CategoryEditVm GetCategoryById(Guid Id) { Category entity = _rep.Categories.GetById(Id); CategoryEditVm vm = new CategoryEditVm() { Id = entity.Id, Name = entity.Name, Type = entity.Type }; vm.ParrentCategory = new BootstrapSelectVm() { SourceList = _rep.Categories.GetAll().Select(x => new SelectListItem() { Text = x.Name, Value = x.Id.ToString() }), SelectedItem = entity.ParrentCategory == null ? null : entity.ParrentCategory.Id.ToString() }; return(vm); }
public async Task <IActionResult> Edit(Guid?id) { if (id == null) { return(NotFound()); } var category = await this.dbContext.Categories.SingleOrDefaultAsync(m => m.Id == id); if (category == null) { return(NotFound()); } var model = new CategoryEditVm() { Id = category.Id, Name = category.Name, Image = category.Image }; return(View(model)); }