Esempio n. 1
0
        public ActionResult Create(Person person)
        {
            if (ModelState.IsValid)
            {
                db.People.Add(person);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(person));
        }
Esempio n. 2
0
        public ActionResult Create(User user)
        {
            if (ModelState.IsValid)
            {
                db.Users.Add(user);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.PersonName = db.People.Where(p => p.Id == user.PersonId).Select(p => p.Name + " " + p.Surname).FirstOrDefault();
            ViewBag.PersonId   = user.PersonId + "";

            return(View(user));
        }
Esempio n. 3
0
        public void GetBook_WithNonExistingId_ReturnsNull()
        {
            BannerEntity banner = new BannerEntity(EBannerType.DEPARTAMENT, "Açougue", DateTime.Now.AddDays(-1), DateTime.Now.AddDays(+30));

            banner.SetSubtitle("Carnes fresquinhas");
            banner.SetDescription("Carnes fresquinhas");
            banner.SetTipText("Açougue");
            banner.SetUrlNavigate("/");

            _context.Banners.Add(banner);
            _context.SaveChanges();
            var ok = _context.Banners.Where(a => a.Id > 0).FirstOrDefault();

            _repository.Add(banner);

            var ba = _repository.Query(a => a.Id > 0).ToList();

            Assert.IsTrue(banner.Id > 0);


            //// Arrange
            //const int nonExistingId = 155;

            //// Act
            //var book = _repository.Get(nonExistingId);

            //// Assert
            //book.Should().BeNull();
        }
Esempio n. 4
0
        public CommentsModel Post(CommentsModel newComment)
        {
            try
            {
                using (WebSiteContext db = new WebSiteContext())
                {
                    var comment = new Comment();
                    comment.CreateDate   = DateTime.Now;
                    comment.ArticleId    = newComment.ArticleId;
                    comment.CommentText  = newComment.CommentText;
                    comment.CommentTitle = newComment.CommentTitle;
                    comment.UserId       = newComment.UserId;
                    comment.UserName     = newComment.UserName;
                    db.Comments.Add(comment);
                    db.SaveChanges();

                    newComment.CommentId  = comment.CommentId;
                    newComment.CreateDate = comment.CreateDate.ToShortDateString();
                    newComment.success    = "ok";

                    newComment.success = new GodaddyEmailController().SendEmail("Somebody Actually Made A comment", comment.UserName + " said: " + comment.CommentText);
                }
            }
            catch (Exception ex)
            {
                newComment.success = Helpers.ErrorDetails(ex);
            }
            return(newComment);
        }
Esempio n. 5
0
        public string Put(Comment updateComment)
        {
            string success = "";

            try
            {
                using (WebSiteContext db = new WebSiteContext())
                {
                    Comment comment = db.Comments.Where(c => c.CommentId == updateComment.CommentId).FirstOrDefault();
                    if (comment != null)
                    {
                        comment.CommentText  = updateComment.CommentText;
                        comment.CommentTitle = updateComment.CommentTitle;

                        db.SaveChanges();
                        success = "ok";
                    }
                    else
                    {
                        success = "comment not found";
                    }
                }
            }
            catch (Exception ex)
            {
                success = Helpers.ErrorDetails(ex);
            }
            return(success);
        }
Esempio n. 6
0
        public string Put(ArticleModel editArticle)
        {
            var success = "";

            try
            {
                using (WebSiteContext db = new WebSiteContext())
                {
                    Article article = db.Articles.Where(a => a.Id.ToString() == editArticle.Id).FirstOrDefault();
                    article.Title          = editArticle.Title;
                    article.CategoryRef    = editArticle.CategoryRef;
                    article.SubCategoryRef = editArticle.SubCategoryRef;
                    article.ImageName      = editArticle.ImageName;
                    article.LastUpdated    = DateTime.Parse(editArticle.LastUpdated);
                    article.ByLineRef      = editArticle.ByLineRef;
                    article.Content        = editArticle.Contents;
                    article.Summary        = editArticle.Summary;

                    db.ArticleTags.RemoveRange(db.ArticleTags.Where(t => t.articleId.ToString() == editArticle.Id));
                    //article.ArticleTags = null;
                    foreach (DbArticleTagModel tagModel in editArticle.Tags)
                    {
                        article.ArticleTags.Add(new ArticleTag()
                        {
                            articleId = article.Id, Id = tagModel.Id, TagName = tagModel.TagName
                        });
                    }

                    db.SaveChanges();
                    success = "ok";
                }
            }
            catch (Exception ex) { success = Helpers.ErrorDetails(ex); }
            return(success);
        }
Esempio n. 7
0
        public string Put(BlogModel editBlog)
        {
            var success = "";

            try
            {
                using (WebSiteContext db = new WebSiteContext())
                {
                    Blog blog = db.Blogs.Where(b => b.Id.ToString() == editBlog.Id).FirstOrDefault();
                    if (blog == null)
                    {
                        success = "article not found";
                    }
                    else
                    {
                        blog.BlogName  = editBlog.Name;
                        blog.Color     = editBlog.Color;
                        blog.BlogOwner = editBlog.Owner;
                        db.SaveChanges();
                        success = "ok";
                    }
                }
            }
            catch (Exception ex) { success = Helpers.ErrorDetails(ex); }
            return(success);
        }
Esempio n. 8
0
        public string Put(ListItemModel editItem)
        {
            var success = "";

            try
            {
                using (WebSiteContext db = new WebSiteContext())
                {
                    ListItem listItem = db.ListItems.Where(i => i.Id == editItem.Id).FirstOrDefault();
                    if (listItem == null)
                    {
                        success = "listItem not found";
                    }
                    else
                    {
                        listItem.ParentId        = editItem.ParentId;
                        listItem.ItemName        = editItem.ItemName;
                        listItem.ItemPriorityRef = editItem.ItemPriorityRef;
                        listItem.ItemStatusRef   = editItem.ItemStatusRef;
                        listItem.AssignedTo      = editItem.AssignedTo;
                        listItem.PercentComplete = editItem.PercentComplete;
                        listItem.Narrative       = editItem.Narrative;
                        if (editItem.DateCompleted != null)
                        {
                            listItem.DateCompleted = DateTime.Parse(editItem.DateCompleted);
                        }

                        db.SaveChanges();
                        success = "ok";
                    }
                }
            }
            catch (Exception ex) { success = Helpers.ErrorDetails(ex); }
            return(success);
        }
Esempio n. 9
0
        public string Post(ListItemModel newItem)
        {
            var success = "";

            try
            {
                ListItem listItem = new ListItem()
                {
                    ListId          = newItem.ListId,
                    Id              = Guid.NewGuid().ToString(),
                    ParentId        = newItem.ParentId,
                    ItemName        = newItem.ItemName,
                    AssignedTo      = newItem.AssignedTo,
                    ItemPriorityRef = newItem.ItemPriorityRef,
                    ItemStatusRef   = newItem.ItemStatusRef,
                    PercentComplete = newItem.PercentComplete,
                    Narrative       = newItem.Narrative,
                    Created         = DateTime.Now
                };

                using (WebSiteContext db = new WebSiteContext())
                {
                    db.ListItems.Add(listItem);
                    db.SaveChanges();
                    success = listItem.Id;
                }
            }
            catch (Exception ex) { success = Helpers.ErrorDetails(ex); }
            return(success);
        }
Esempio n. 10
0
        public string Put(BlogEntryModel editBlogEntry)
        {
            var success = "";

            try
            {
                using (WebSiteContext db = new WebSiteContext())
                {
                    BlogEntry blogEntry = db.BlogEntries.Where(b => b.Id.ToString() == editBlogEntry.Id).FirstOrDefault();
                    if (blogEntry == null)
                    {
                        success = "article not found";
                    }
                    else
                    {
                        blogEntry.Title       = editBlogEntry.Title;
                        blogEntry.ImageName   = editBlogEntry.ImageName;
                        blogEntry.Summary     = editBlogEntry.Summary;
                        blogEntry.Content     = editBlogEntry.Content;
                        blogEntry.LastUpdated = DateTime.Now;
                        db.SaveChanges();
                        success = "ok";
                    }
                }
            }
            catch (Exception ex) { success = Helpers.ErrorDetails(ex); }
            return(success);
        }
Esempio n. 11
0
        public string Post(BlogEntryModel newBlogEntry)
        {
            var success = "";

            try
            {
                BlogEntry blogEntry = new BlogEntry();
                blogEntry.BlogId      = newBlogEntry.BlogId;
                blogEntry.Id          = Guid.NewGuid().ToString();
                blogEntry.Title       = newBlogEntry.Title;
                blogEntry.ImageName   = newBlogEntry.ImageName;
                blogEntry.Summary     = newBlogEntry.Summary;
                blogEntry.Content     = newBlogEntry.Content;
                blogEntry.Created     = DateTime.Now;
                blogEntry.LastUpdated = DateTime.Now;

                using (WebSiteContext db = new WebSiteContext())
                {
                    db.BlogEntries.Add(blogEntry);
                    db.SaveChanges();
                    success = blogEntry.Id.ToString();
                }
            }
            catch (Exception ex) { success = Helpers.ErrorDetails(ex); }
            return(success);
        }
Esempio n. 12
0
        public string Post(ArticleModel articleModel)
        {
            var success = "";

            try
            {
                Article newArticle = new Article();
                if (articleModel.Id == null)
                {
                    newArticle.Id = Guid.NewGuid().ToString();
                }
                else
                {
                    newArticle.Id = articleModel.Id;
                }
                newArticle.Title          = articleModel.Title;
                newArticle.CategoryRef    = articleModel.CategoryRef;
                newArticle.SubCategoryRef = articleModel.SubCategoryRef;
                newArticle.ImageName      = articleModel.ImageName;
                newArticle.Created        = DateTime.Now;
                newArticle.LastUpdated    = DateTime.Parse(articleModel.LastUpdated);
                newArticle.Content        = articleModel.Contents;
                newArticle.Summary        = articleModel.Summary;
                newArticle.ByLineRef      = articleModel.ByLineRef;

                foreach (DbArticleTagModel tag in articleModel.Tags)
                {
                    if (tag.TagName != null)
                    {
                        newArticle.ArticleTags.Add(new ArticleTag()
                        {
                            TagName = tag.TagName, TagCategoryRef = tag.TagCategoryRef
                        });
                    }
                }
                using (WebSiteContext db = new WebSiteContext())
                {
                    db.Articles.Add(newArticle);
                    db.SaveChanges();
                    success = newArticle.Id.ToString();
                }
            }
            catch (Exception ex)
            {
                success = Helpers.ErrorDetails(ex);
            }
            return(success);
        }
Esempio n. 13
0
        public string Post(DbArticleTagModel tag)
        {
            var success = "";

            try
            {
                var dbTag = new ArticleTag();
                dbTag.TagName   = tag.TagName;
                dbTag.articleId = tag.ArticleId;
                using (WebSiteContext db = new WebSiteContext())
                {
                    db.ArticleTags.Add(dbTag);
                    db.SaveChanges();
                    success = "ok";
                }
            }
            catch (Exception ex) { success = Helpers.ErrorDetails(ex); }
            return(success);
        }
Esempio n. 14
0
        public string Post(BlogModel newBlog)
        {
            var success = "";

            try
            {
                using (WebSiteContext db = new WebSiteContext())
                {
                    Blog blog = new Blog();
                    blog.Id        = Guid.NewGuid().ToString();
                    blog.BlogName  = newBlog.Name;
                    blog.Color     = newBlog.Color;
                    blog.BlogOwner = newBlog.Owner;

                    db.Blogs.Add(blog);
                    db.SaveChanges();
                    success = blog.Id.ToString();
                }
            }
            catch (Exception ex) { success = Helpers.ErrorDetails(ex); }
            return(success);
        }
Esempio n. 15
0
        public string Put(ListModel editList)
        {
            var success = "";

            try
            {
                using (WebSiteContext db = new WebSiteContext())
                {
                    ToDoList list = db.Lists.Where(l => l.Id == editList.Id).FirstOrDefault();
                    if (list == null)
                    {
                        success = "list not found";
                    }
                    else
                    {
                        list.ListName = editList.ListName;
                        db.SaveChanges();
                        success = "ok";
                    }
                }
            }
            catch (Exception ex) { success = Helpers.ErrorDetails(ex); }
            return(success);
        }
Esempio n. 16
0
        public string Post(ListModel newList)
        {
            var success = "";

            try
            {
                ToDoList toDoList = new ToDoList()
                {
                    Id        = Guid.NewGuid().ToString(),
                    Created   = DateTime.Now,
                    ListName  = newList.ListName,
                    ListOwner = newList.ListOwner
                };

                using (WebSiteContext db = new WebSiteContext())
                {
                    db.Lists.Add(toDoList);
                    db.SaveChanges();
                    success = toDoList.Id;
                }
            }
            catch (Exception ex) { success = Helpers.ErrorDetails(ex); }
            return(success);
        }