Пример #1
0
        public ActionResult CreateEdit(NccImageSlider model, string save, string[] itemPath, string[] description)
        {
            bool isSuccess = false;

            ViewBag.MessageType = "ErrorMessage";
            ViewBag.Message     = "Error occoured. Please fill up all field correctly.";

            if (ModelState.IsValid)
            {
                //unique name check
                model.Name = model.Name.Trim();
                var itemCount = _nccImageSliderService.LoadAll(true, 0, model.Name).Where(x => x.Id != model.Id).ToList().Count();
                if (itemCount > 0)
                {
                    ViewBag.Message = "Duplicate name found.";
                }
                else
                {
                    model.ImageItems = new List <NccImageSliderItem>();
                    for (int i = 0; i < itemPath.Count(); i++)
                    {
                        var tempItemPath    = string.IsNullOrEmpty(itemPath[i]) ? "" : itemPath[i];
                        var tempDescription = string.IsNullOrEmpty(description[i]) ? "" : description[i];

                        model.ImageItems.Add(new NccImageSliderItem()
                        {
                            Name = "Name_" + tempItemPath.Replace("/", "_"), Path = tempItemPath, Description = tempDescription, Order = i
                        });
                    }

                    if (model.Id > 0)
                    {
                        _nccImageSliderService.Update(model);
                        isSuccess           = true;
                        ViewBag.MessageType = "SuccessMessage";
                        ViewBag.Message     = "Data updated successfull.";
                    }
                    else
                    {
                        _nccImageSliderService.Save(model);
                        isSuccess           = true;
                        ViewBag.MessageType = "SuccessMessage";
                        ViewBag.Message     = "Data saved successfull.";
                    }
                }
            }

            if (isSuccess == true && save == "Save")
            {
                return(RedirectToAction("Manage"));
            }
            return(View(model));
        }
Пример #2
0
        public ActionResult CreateEdit(NccImageSlider item)
        {
            ViewBag.MessageType = "ErrorMessage";
            ViewBag.Message     = "Error occoured. Please fill up all field correctly.";

            if (ModelState.IsValid)
            {
                if (item.Id > 0)
                {
                    _nccImageSliderService.Update(item);
                    ViewBag.MessageType = "SuccessMessage";
                    ViewBag.Message     = "Notice updated successfull.";
                }
                else
                {
                    _nccImageSliderService.Save(item);
                    ViewBag.MessageType = "SuccessMessage";
                    ViewBag.Message     = "Notice save successfull.";
                }
                //TempData["SuccessMessage"] = "Notice save successfull.";
            }

            return(View(item));
        }