コード例 #1
0
        public async Task <IActionResult> Edit(int id, AdministrationCategoryViewModel category)
        {
            if (id != category.Id)
            {
                return(this.NotFound());
            }

            if (this.ModelState.IsValid)
            {
                try
                {
                    await this.categoryService.UpdateAsync(category);
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!this.CategoryExists(category.Id))
                    {
                        return(this.NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }

                return(this.RedirectToAction(nameof(this.Index)));
            }

            return(this.View(category));
        }
コード例 #2
0
        public async Task UpdateAsync(AdministrationCategoryViewModel category)
        {
            var categoryToUpdate = this.categoriesRepository
                                   .AllAsNoTrackingWithDeleted()
                                   .FirstOrDefault(x => x.Id == category.Id);

            categoryToUpdate.Name       = category.Name;
            categoryToUpdate.CreatedOn  = category.CreatedOn;
            categoryToUpdate.DeletedOn  = category.DeletedOn;
            categoryToUpdate.IsDeleted  = category.IsDeleted;
            categoryToUpdate.ModifiedOn = category.ModifiedOn;

            this.categoriesRepository.Update(categoryToUpdate);
            await this.categoriesRepository.SaveChangesAsync();
        }