public ActionResult Create(PortfolioCategoryModel model)
        {
            if (ModelState.IsValid)
            {
                var portfolioCategory = new PortfolioCategory
                {
                    Name     = model.Name,
                    IsActive = model.IsActive
                };

                var result = portfolioCategoryService.Insert(portfolioCategory);
                if (result)
                {
                    this.NotifySuccess("Successfully saved.");
                }
                else
                {
                    this.NotifyError("Item can not saved!");
                }

                var urlRecord = new UrlRecord
                {
                    EntityId   = portfolioCategory.Id,
                    EntityName = nameof(PortfolioCategory),
                    Slug       = model.Name.ToUrlSlug()
                };
                urlService.Save(urlRecord);

                return(RedirectToAction("Edit", new { Id = portfolioCategory.Id }));
            }

            return(View(model));
        }
        public ActionResult Create()
        {
            var model = new PortfolioCategoryModel();

            model.IsActive = true;
            return(View(model));
        }
        /// <summary>
        /// PortfolioCategory Edit
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult Edit(int?id)
        {
            if (!id.HasValue)
            {
                return(RedirectToAction("List"));
            }

            var portfolioCategory = portfolioCategoryService.GetById(id.Value);

            if (portfolioCategory == null)
            {
                this.NotifyError("Item not found.");
                return(RedirectToAction("List"));
            }

            var model = new PortfolioCategoryModel
            {
                Id             = portfolioCategory.Id,
                Name           = portfolioCategory.Name,
                IsActive       = portfolioCategory.IsActive,
                PortfolioCount = portfolioService.GetCount(portfolioCategory.Id),
                Url            = urlService.GetUrl(portfolioCategory.Id, nameof(PortfolioCategory))
            };

            return(View(model));
        }
 private PortfolioModel GetPortfolioModel(long id)
 {
     try
     {
         PortfolioModel portfolioModel = new PortfolioModel();
         Portfolio      portfolio      = db.Portfolios.Where(x => x.id == id).SingleOrDefault();
         if (portfolio != null)
         {
             portfolioModel.background = portfolio.background;
             portfolioModel.header     = portfolio.header;
             List <PortfolioCategory> portfolioCategories = db.PortfolioCategories.Where(x => x.portfolioID == id).ToList();
             if (portfolioCategories != null)
             {
                 List <PortfolioCategoryModel> portfolioCategoryModels = new List <PortfolioCategoryModel>();
                 foreach (PortfolioCategory portfolioCategory in portfolioCategories)
                 {
                     PortfolioCategoryModel portfolioCategoryModel = new PortfolioCategoryModel();
                     portfolioCategoryModel.category = portfolioCategory.category;
                     List <PortfolioCategoryImageRelationship> portfolioCategoryImageRelationships =
                         db.PortfolioCategoryImageRelationships.Where(x => x.portfolioCategoryID == portfolioCategory.id).ToList();
                     if (portfolioCategoryImageRelationships != null)
                     {
                         List <string> images = new List <string>();
                         foreach (PortfolioCategoryImageRelationship portfolioCategoryImage in portfolioCategoryImageRelationships)
                         {
                             images.Add(portfolioCategoryImage.image);
                             portfolioCategoryModel.images = images;
                         }
                         portfolioCategoryModels.Add(portfolioCategoryModel);
                         portfolioModel.portfolioCategories = portfolioCategoryModels;
                     }
                 }
             }
         }
         return(portfolioModel);
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
         return(null);
     }
 }
        public ActionResult Edit(PortfolioCategoryModel model)
        {
            if (ModelState.IsValid)
            {
                var portfolioCategory = portfolioCategoryService.GetById(model.Id);
                if (portfolioCategory == null)
                {
                    this.NotifyError("Item not found.");
                    return(RedirectToAction("List"));
                }

                portfolioCategory.Name     = model.Name;
                portfolioCategory.IsActive = model.IsActive;

                var result = portfolioCategoryService.Update(portfolioCategory);
                if (result)
                {
                    this.NotifySuccess("Successfully saved.");
                }
                else
                {
                    this.NotifyError("Item can not saved!");
                }

                urlService.Save(new UrlRecord()
                {
                    EntityId   = portfolioCategory.Id,
                    EntityName = nameof(PortfolioCategory),
                    Slug       = model.Name.ToUrlSlug()
                });

                return(RedirectToAction("Edit", new { id = model.Id }));
            }

            return(View(model));
        }