예제 #1
0
        public ActionResult Create(CategoryFormServiceModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            string name = model.Name;

            if (this.categoryServive.NameExists(name))
            {
                TempData.AddErrorMessage(string.Format(WebConstants.EntryExists, name));
                return(View(model));
            }

            bool success = this.categoryServive.Create(name);

            if (!success)
            {
                return(BadRequest());
            }

            TempData.AddSuccessMessage(string.Format(
                                           WebConstants.SuccessfullEntityOperation,
                                           Category,
                                           WebConstants.Added));

            return(RedirectToAction(nameof(All)));
        }
예제 #2
0
        public async Task <IActionResult> Create(CategoryFormServiceModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            await this.categories.Create(model.Name);

            TempData.AddSuccessMessage($"Category {model.Name} created successfully.");

            return(RedirectToAction(nameof(All)));
        }
예제 #3
0
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(BadRequest());
            }

            CategoryFormServiceModel model = this.categoryServive.GetForm(id.Value);

            if (model == null)
            {
                return(BadRequest());
            }

            return(View(model));
        }
예제 #4
0
        public async Task <IActionResult> Edit(int id, CategoryFormServiceModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var categoryExist = await this.categories.Exist(id);

            if (!categoryExist)
            {
                return(NotFound());
            }

            await this.categories.Edit(id, model.Name);

            return(RedirectToAction(nameof(All)));
        }
예제 #5
0
        public ActionResult Edit(int?id, CategoryFormServiceModel model)
        {
            if (id == null)
            {
                return(BadRequest());
            }

            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            string oldName = this.categoryServive.GetName(id.Value);

            if (oldName == null)
            {
                return(BadRequest());
            }

            string newName = model.Name;

            if (this.categoryServive.NameExists(newName) &&
                oldName != newName)
            {
                TempData.AddErrorMessage(string.Format(WebConstants.EntryExists, newName));
                return(View(model));
            }

            bool success = this.categoryServive.Edit(id.Value, newName);

            if (!success)
            {
                return(BadRequest());
            }

            TempData.AddSuccessMessage(string.Format(
                                           WebConstants.SuccessfullEntityOperation,
                                           Category,
                                           WebConstants.Edited));

            return(RedirectToAction(nameof(All)));
        }