コード例 #1
0
        public UpdateCategoryViewModel GetCategoryForUpdateById(short CategoryRowID)
        {
            try
            {
                UpdateCategoryViewModel model = new UpdateCategoryViewModel();
                var entity = db.MasterCategories.Find(CategoryRowID);

                if (entity != null)
                {
                    model.CategoryRowID = entity.CategoryRowID;
                    model.CategoryName  = entity.CategoryName;
                    model.Status        = entity.Status;
                }
                else
                {
                    throw new Exception("Invalid Id!");
                }

                return(model);
            }
            catch (Exception)
            {
                throw;
            }
        }
コード例 #2
0
        public async Task <ApplicationResult <CategoryDto> > Update(UpdateCategoryViewModel model)
        {
            try
            {
                var getExistCategory = await _context.Categories.FindAsync(model.Id);

                if (getExistCategory == null)
                {
                    return(new ApplicationResult <CategoryDto>
                    {
                        Result = new CategoryDto(),
                        Succeeded = false,
                        ErrorMessage = "Böyle bir Kategori bulunamadı"
                    });
                }
                var modifierUser = await _userManager.FindByIdAsync(model.ModifiedById);

                getExistCategory.ModifiedBy = modifierUser.UserName;
                _mapper.Map(model, getExistCategory);
                _context.Update(getExistCategory);
                await _context.SaveChangesAsync();

                return(await Get(getExistCategory.Id));
            }
            catch (Exception e)
            {
                return(new ApplicationResult <CategoryDto>
                {
                    Result = new CategoryDto(),
                    Succeeded = false,
                    ErrorMessage = e.Message
                });
            }
        }
        public ActionResult Edit(UpdateCategoryViewModel viewModel)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(View(viewModel));
                }


                var toBeUpdaetdCategory = _unitOfWork.CategoryRepository.Get(x => x.Id == viewModel.CategoryId);
                toBeUpdaetdCategory.Name        = viewModel.Name;
                toBeUpdaetdCategory.Description = viewModel.Description;
                _unitOfWork.CategoryRepository.Update(toBeUpdaetdCategory);
                if (_unitOfWork.Complete() > 0)
                {
                    return(RedirectToAction(nameof(Index)));
                }

                return(View(viewModel));
            }
            catch
            {
                return(View(viewModel));
            }
        }
コード例 #4
0
        public async Task <IActionResult> UpdateCategory([FromBody] UpdateCategoryViewModel category_model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (category_model._id_category < 1)
            {
                return(BadRequest());
            }

            var category = await _context.Categories.FirstOrDefaultAsync(c => c._id_category == category_model._id_category);

            if (category == null)
            {
                return(NotFound());
            }
            category.name        = category_model.name;
            category.description = category_model.description;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                return(BadRequest());
            }

            return(Ok());
        }
コード例 #5
0
        public async Task <IActionResult> Edit(Guid id, UpdateCategoryViewModel model)
        {
            //Hata durumunda geri dönecek model
            var errorReturnModel = model;

            if (ModelState.IsValid)
            {
                if (id != model.Id)
                {
                    ModelState.AddModelError(string.Empty, "Bir hata oluştu!");
                }
                else
                {
                    var getService = await _categoryService.Get(id);

                    model.CreatedById  = getService.Result.CreatedById;
                    model.Id           = getService.Result.Id;
                    model.ModifiedById = User.FindFirst(ClaimTypes.NameIdentifier).Value;
                    var updateService = await _categoryService.Update(model);

                    if (updateService.Succeeded)
                    {
                        return(RedirectToAction("Details", new { id }));
                    }
                    ModelState.AddModelError(string.Empty, updateService.ErrorMessage);
                }
            }

            return(View(errorReturnModel));
        }
コード例 #6
0
        public void Update(UpdateCategoryViewModel model)
        {
            _unitOfWorkScope.BeginTransaction();

            var category = _categoryRepository.GetById(model.Id);

            if (category == null)
            {
                _unitOfWorkScope.Commit();
                throw new Exception(ExceptionMessages.CategoryException.NOT_FOUND);
            }
            if (category.IsDefault && model.IsDefault == false)
            {
                _unitOfWorkScope.Commit();
                throw new Exception(ExceptionMessages.CategoryException.DISELECT_DEFAULT);
            }
            category.Name      = model.Name;
            category.Status    = model.Status;
            category.IsDefault = model.IsDefault;

            var isUnique = _categoryRepository.CheckUniqueness(category);

            if (!isUnique)
            {
                _unitOfWorkScope.Commit();
                throw new Exception(ExceptionMessages.CategoryException.ALREADY_EXISTS);
            }

            if (!model.Status && model.IsDefault)
            {
                _unitOfWorkScope.Commit();
                throw new Exception(ExceptionMessages.CategoryException.CHANGE_STATUS_ISDEFAULT);
            }

            if (!model.IsDefault)
            {
                var active = _categoryRepository.GetActive();

                if (active == null)
                {
                    _unitOfWorkScope.Commit();
                    throw new Exception("Cant change default value");
                }
            }
            // check if there is some other category that is default
            if (model.IsDefault)
            {
                var defaultCategory = _categoryRepository.GetDefaultCategory(category.Id);
                if (defaultCategory != null)
                {
                    defaultCategory.IsDefault = false;
                    _categoryRepository.Update(defaultCategory);
                }
            }


            _categoryRepository.Update(category);

            _unitOfWorkScope.Commit();
        }
コード例 #7
0
        public IActionResult Update(int id, UpdateCategoryViewModel vm, IFormFile ImgPath)
        {
            Category cat = _catRepo.GetSingle(c => c.CategoryId == id);

            if (ModelState.IsValid && cat != null)
            {
                cat.Name        = vm.Name;
                cat.Description = vm.Description;

                if (ImgPath != null)
                {
                    string uploadPath = Path.Combine(_environment.WebRootPath, "Uploads");
                    uploadPath = Path.Combine(uploadPath, User.Identity.Name);
                    Directory.CreateDirectory(Path.Combine(uploadPath, cat.Name));


                    string fileName = Path.GetFileName(ImgPath.FileName);

                    using (FileStream fs = new FileStream(Path.Combine(uploadPath, cat.Name, fileName), FileMode.Create))
                    {
                        ImgPath.CopyTo(fs);
                    }

                    cat.ImgPath = Path.Combine(User.Identity.Name, cat.Name, fileName);
                }

                _catRepo.Update(cat);

                return(RedirectToAction("Index"));
            }

            ModelState.AddModelError("", "Information required!");

            return(View(vm));
        }
コード例 #8
0
 public static UpdateCategoryDto ToDto(this UpdateCategoryViewModel source)
 {
     return(new UpdateCategoryDto
     {
         Title = source.Title,
         Id = source.Id
     });
 }
コード例 #9
0
        public UpdateCategoryPage(Category category)
        {
            InitializeComponent();
            var viewModel = new UpdateCategoryViewModel();

            viewModel.Category = category;
            BindingContext     = viewModel;
        }
コード例 #10
0
        public IActionResult Update(int categoryId)
        {
            UpdateCategoryViewModel model = new UpdateCategoryViewModel
            {
                CategoryId = categoryId
            };

            return(View(model));
        }
コード例 #11
0
        public async Task <IActionResult> UpdateImage(int categoryId)
        {
            var categoryViewModel = new UpdateCategoryViewModel()
            {
                Category = await _categoryService.GetCategoryByIdAsync(categoryId)
            };

            return(View("UploadImageView", categoryViewModel));
        }
コード例 #12
0
        public ActionResult Update(UpdateCategoryViewModel model)
        {
            if (!ModelState.IsValid)
            {
                Helpers.InvalidModelState(ModelState);
            }

            _categoryService.Update(model);
            return(Json(true));
        }
コード例 #13
0
ファイル: CategoryController.cs プロジェクト: JAQ1/GrandeGift
        public IActionResult Update()
        {
            IEnumerable <Category> categories = _categoryRepo.Query(c => c.Active == true);

            UpdateCategoryViewModel vm = new UpdateCategoryViewModel()
            {
                Categories = categories
            };

            return(View(vm));
        }
コード例 #14
0
ファイル: CategoryController.cs プロジェクト: zblash/Convice
        public async Task <IActionResult> Update(int id)
        {
            var category = await _categoryService.GetById(id);

            UpdateCategoryViewModel model = new UpdateCategoryViewModel
            {
                Category = category
            };

            return(View(model));
        }
コード例 #15
0
        public async Task <IActionResult> UpdateCategory(UpdateCategoryViewModel updateViewModel)
        {
            var category = await _mediator.Send(new CreateOrUpdateCategoryCommand
            {
                UserId = User.Identity.UserId(),
                Name   = updateViewModel.Name,
                Id     = updateViewModel.Id
            });

            return(Ok(_mapper.Map <CategoryViewModel>(category)));
        }
コード例 #16
0
ファイル: CategoryController.cs プロジェクト: JAQ1/GrandeGift
        public IActionResult Update(UpdateCategoryViewModel vm)
        {
            var user     = GetCurrentUserAsync().Result;
            var category = _categoryRepo.GetSingle(c => c.CategoryId == vm.SelectedCategoryId);

            category.Name   = vm.Name;
            category.UserId = user.Id;

            _categoryRepo.Update(category);

            return(RedirectToAction("Index", "Admin"));
        }
コード例 #17
0
 public JsonResult UpdateCategory(UpdateCategoryViewModel model)
 {
     try
     {
         _categoryService.Update(base.ModelMapper.ConvertToModel(model));
         return(Json(true));
     }
     catch (Exception ex)
     {
         return(Json(ex));
     }
 }
コード例 #18
0
        public IActionResult Update(int id)
        {
            var dto = Db.Get <Category>(id);

            var model = new UpdateCategoryViewModel {
                ID        = dto.ID,
                Name      = dto.Name,
                IsDeleted = dto.Deleted
            };

            return(View(model));
        }
コード例 #19
0
        public ActionResult AddSubcategory(UpdateCategoryViewModel viewModel)
        {
            SubCategory addSub = new SubCategory
            {
                SubCategoryName = viewModel.SubcategoryName,
                CategoryId      = viewModel.CategoryId
            };

            ApplicationDbContext.SubCategories.Add(addSub);
            ApplicationDbContext.SaveChanges();

            return(RedirectToAction("LoadSubCategory", new { categoryId = viewModel.CategoryId }));
        }
コード例 #20
0
        public ActionResult GetUpdateCategory(int categoryId)
        {
            var category = ApplicationDbContext.Categories.First(i => i.CategoryId == categoryId);

            var viewModel = new UpdateCategoryViewModel
            {
                CategoryId       = category.CategoryId,
                CategoryName     = category.CategoryName,
                FilterButtonName = category.FilterButtonName
            };

            return(View("UpdateCategory", viewModel));
        }
コード例 #21
0
        public async Task <ActionResult> UpdateCategory(int id, UpdateCategoryViewModel updateCategoryViewModel)
        {
            var category = await categoryRepository.GetByIdAsync(id);

            if (category == null)
            {
                return(NotFound());
            }

            await categoryRepository.UpdateAsync(category, updateCategoryViewModel.Title, updateCategoryViewModel.Types);

            return(NoContent());
        }
コード例 #22
0
        public IActionResult UpdateCategory(UpdateCategoryViewModel model)
        {
            var resultModel = new ApiResultModel();
            int code;

            try
            {
                if (!ModelState.IsValid)
                {
                    code = StatusCodes.Status406NotAcceptable;
                    resultModel.message = "Lütfen gerekli alanları doldurunuz!";
                    resultModel.errors  = new List <ApiError>();
                    foreach (var field in ModelState)
                    {
                        foreach (var error in field.Value.Errors)
                        {
                            resultModel.errors.Add(new ApiError()
                            {
                                field = field.Key, errorMessage = error.ErrorMessage
                            });
                        }
                    }
                }
                else
                {
                    var category = db.GetRepository <Category>().Get(q => q.Id == model.categoryId).FirstOrDefault();
                    if (category == null)
                    {
                        code = StatusCodes.Status400BadRequest;
                        resultModel.message = "İlgili kategori bulunamadı!";
                    }
                    else
                    {
                        category.Name      = model.categoryName;
                        category.IsVisible = model.categoryIsVisible;
                        db.Commit();
                        code = StatusCodes.Status201Created;
                        resultModel.message = "Kategori güncelleme işlemi başarılı";
                        resultModel.data    = category;
                    }
                }
            }
            catch (Exception e)
            {
                code = StatusCodes.Status400BadRequest;
                resultModel.message = "Kategori Detayları alınırken hata oluştu!";
            }
            return(StatusCode(code, resultModel));
        }
コード例 #23
0
ファイル: CategoryController.cs プロジェクト: zblash/Convice
        public async Task <IActionResult> Update(Category category)
        {
            if (!ModelState.IsValid)
            {
                UpdateCategoryViewModel model = new UpdateCategoryViewModel
                {
                    Category = category
                };
                return(View(model));
            }
            await _categoryService.Update(category);

            TempData["message"] = $"Kategori Güncellendi {category.Id}";
            return(RedirectToAction("List"));
        }
コード例 #24
0
        public async Task <IActionResult> Edit(Guid id)
        {
            var getService = await _categoryService.Get(id);

            UpdateCategoryViewModel model = new UpdateCategoryViewModel
            {
                Id              = getService.Result.Id,
                CreatedById     = getService.Result.CreatedById,
                ModifiedById    = User.FindFirst(ClaimTypes.NameIdentifier).Value,
                CategoryName    = getService.Result.CategoryName,
                CategoryUrlName = getService.Result.CategoryUrlName
            };

            return(View(model));
        }
コード例 #25
0
        public async Task <IActionResult> Update(int categoryId, UpdateCategoryViewModel model)
        {
            if (ModelState.IsValid)
            {
                var identityUser = await _userManager.GetUserAsync(HttpContext.User);

                string path = null;
                if (model.TitleImage != null)
                {
                    FileSaverResult fileSaverResult = await _fileSaver.SaveCategoryTitleImage(_appEnvironment.WebRootPath, model.TitleImage);

                    if (fileSaverResult.IsSuccessful)
                    {
                        path = fileSaverResult.Path;
                    }
                    else
                    {
                        ModelState.AddModelError("", "Can't save image");
                    }
                }

                var result = await Mediator.Send(new UpdateCategoryCommand
                {
                    CategoryId     = categoryId,
                    Title          = model.Title,
                    IdentityUserId = identityUser.Id,
                    TitleImagePath = path,
                });

                if (result.IsSuccessful)
                {
                    if (path != null)
                    {
                        using (var fileStream = new FileStream(_appEnvironment.WebRootPath + path, FileMode.Create))
                        {
                            await model.TitleImage.CopyToAsync(fileStream);
                        }
                    }
                    return(RedirectToAction("Index", "Category"));
                }
                else
                {
                    ModelState.AddModelError("", result.Message);
                }
            }
            return(View());
        }
コード例 #26
0
        public ActionResult UpdateCategory(UpdateCategoryViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(viewModel));
            }

            Category categoryToUpdate = ApplicationDbContext.Categories
                                        .First(i => i.CategoryId == viewModel.CategoryId);

            categoryToUpdate.CategoryName     = viewModel.CategoryName;
            categoryToUpdate.FilterButtonName = viewModel.FilterButtonName;

            ApplicationDbContext.SaveChanges();

            return(View(viewModel));
        }
        // GET: Category/Edit/5
        public ActionResult Edit(int id)
        {
            var category = _unitOfWork.CategoryRepository.Get(x => x.Id == id);

            if (category == null)
            {
                return(NotFound());
            }
            var viewModel = new UpdateCategoryViewModel()
            {
                CategoryId  = category.Id,
                Description = category.Description,
                Name        = category.Name
            };

            return(View(viewModel));
        }
コード例 #28
0
        public IActionResult Update(UpdateCategoryViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var dto = Db.Get <Category>(model.ID);

            var updated = dto.WithUpdates(name: model.Name);

            Db.InsertOrUpdate(updated);

            UnitOfWork.CommitChanges();

            return(RedirectToAction(nameof(Index)));
        }
コード例 #29
0
 public void UpdateCategory(UpdateCategoryViewModel model)
 {
     try
     {
         if (model != null && model.CategoryRowID > 0)
         {
             db.MasterCategories.Single(c => c.CategoryRowID == model.CategoryRowID).CategoryName = model.CategoryName;
         }
         else
         {
             throw new Exception("Category could not be blank!");
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
コード例 #30
0
        public IActionResult Update(int id)
        {
            var category =
                _categoryService
                .GetCategoryBase(id);

            if (category == null)
            {
                return(NotFound());
            }

            var model = new UpdateCategoryViewModel()
            {
                Title = category.Title
            };

            return(View(model));
        }