Beispiel #1
0
 static private Core.Models.Content.ContentItem Update(Core.Models.Content.ContentItem content, DataModel.Entities db, DataModel.Content dbContent)
 {
     dbContent.Title      = !string.IsNullOrEmpty(content.Title) && content.Title != dbContent.Title ? content.Title : dbContent.Title;
     dbContent.Body       = !string.IsNullOrEmpty(content.Body) && content.Body != dbContent.Body ? content.Body : dbContent.Body;
     dbContent.CategoryId = content.CategoryId != null && content.CategoryId != dbContent.CategoryId ? content.CategoryId : dbContent.CategoryId;
     dbContent.UserId     = content.UserId != null && content.UserId != dbContent.UserId ? content.UserId : dbContent.UserId;
     dbContent.Type       = content.Type != dbContent.Type ? content.Type : dbContent.Type;
     dbContent.Status     = content.Status != dbContent.Status ? content.Status : dbContent.Status;
     db.SaveChanges();
     return(content);
 }
Beispiel #2
0
 public ActionResult Create(Core.Models.Content.ContentItem content)
 {
     try
     {
         var user = (Core.Models.User.UserItem)(ViewBag.User);
         if (ModelState.IsValid)
         {
             content.Id     = Guid.NewGuid();
             content.UserId = user.Id;
             Core.Helpers.Content.ContentHelper.Save(content);
         }
         return(RedirectToAction("Index"));
     }
     catch (Exception ex)
     {
         TempData["Error"] = ex.Message;
     }
     content.Categories = Core.Helpers.Category.CategoryHelper.GetAllCategoriesForList();
     return(View(content));
 }
Beispiel #3
0
 static public Core.Models.Content.ContentItem Save(Core.Models.Content.ContentItem content)
 {
     using (var db = new DataModel.Entities())
     {
         var result = (from i in db.Contents where i.Id == content.Id && i.Deleted == null select i).SingleOrDefault();
         if (result == null)
         {
             var url = Core.Helpers.BaseHelper.ConvertToUrl(content.Title);
             content.Url = url;
             var row = 0;
             while ((from i in db.Contents where i.Url == content.Url select i).SingleOrDefault() != null)
             {
                 row++;
                 content.Url = $"{url}-{row}";
             }
             return(Create(content, db));
         }
         return(Update(content, db, result));
     }
 }
Beispiel #4
0
        static private Core.Models.Content.ContentItem Create(Core.Models.Content.ContentItem content, DataModel.Entities db)
        {
            var newContent = new DataModel.Content()
            {
                Id          = content.Id,
                Title       = content.Title,
                Description = content.Description,
                Url         = content.Url,
                Body        = content.Body,
                ContentDate = content.ContentDate,
                CategoryId  = content.CategoryId,
                UserId      = content.UserId,
                Type        = content.Type,
                Status      = content.Status,
                Created     = DateTime.Now
            };

            db.Contents.Add(newContent);
            db.SaveChanges();
            return(content);
        }
Beispiel #5
0
 public ActionResult Create(Guid?id)
 {
     try
     {
         if (id == null)
         {
             return(RedirectToAction(nameof(Index)));
         }
         var content = new Core.Models.Content.ContentItem
         {
             Categories = Core.Helpers.Category.CategoryHelper.GetAllCategoriesForList(),
             CategoryId = (Guid)id
         };
         return(View(content));
     }
     catch (Exception ex)
     {
         TempData["Error"] = ex.Message;
     }
     return(View());
 }