Ejemplo n.º 1
0
        public PostCategory Create(string name)
        {
            var category = new PostCategory() { Name = name };

            this.categories.Add(category);

            this.categories.Save();

            return category;
        }
Ejemplo n.º 2
0
        public PostCategory EnsureCategory(string name)
        {
            var category = this.postCategories.All().FirstOrDefault(x => x.Name == name);
            if (category != null)
            {
                return category;
            }

            category = new PostCategory { Name = name };
            this.postCategories.Add(category);
            this.postCategories.Save();
            return category;
        }
Ejemplo n.º 3
0
        private static Post ProcessMessage(string subject, string messageBody, string expectedCategory, IEnumerable <MailAttachment> attachments, DateTime?expectedPositionDateTime, Position expectedPosition)
        {
            var post = new Post();

            var postRepositoryMock = MockRepository.GenerateMock <IPostRepository>();

            postRepositoryMock.Expect(b => b.Create()).Return(post);
            postRepositoryMock.Expect(b => b.SubmitChanges());

            var postCategory = new PostCategory();

            var postCategoryRepositoryMock = MockRepository.GenerateMock <IPostCategoryRepository>();

            postCategoryRepositoryMock.Expect(b => b.GetByTitle(expectedCategory)).Return(postCategory);


            var pictureRepositoryMock = MockRepository.GenerateMock <IPictureRepository>();

            if (attachments != null)
            {
                foreach (var attachment in attachments)
                {
                    pictureRepositoryMock.Expect(m => m.AddPictureToAlbum("mailClientPicturesAlbumID", null, attachment.Name, "", "", expectedPositionDateTime, expectedPosition))
                    .Constraints(new[] { RM.Is.Equal("mailClientPicturesAlbumID"), new StreamConstraint(attachment.Data), RM.Is.Equal(attachment.Name), RM.Is.Equal(""), RM.Is.Equal(""), RM.Is.Equal(expectedPositionDateTime), RM.Is.Equal(expectedPosition) })
                    .Return(
                        new Picture
                    {
                        PictureUri   = new Uri("http://" + attachment.Name),
                        ThumbnailUri = new Uri("http://thumbnail." + attachment.Name),
                        Title        = attachment.Name
                    });
                }
            }

            var parsedMessage = new ParsedMessage("*****@*****.**", "*****@*****.**", subject, messageBody, attachments);

            var postMessageProcessor = new PostMessageProcessor(postRepositoryMock, postCategoryRepositoryMock, pictureRepositoryMock);

            postMessageProcessor.ProcessMessage(parsedMessage);

            postRepositoryMock.VerifyAllExpectations();
            postCategoryRepositoryMock.VerifyAllExpectations();
            pictureRepositoryMock.VerifyAllExpectations();

            return(post);
        }
Ejemplo n.º 4
0
 // PUT api/<controller>
 public HttpResponseMessage Put(HttpRequestMessage message, PostCategory postCategory)
 {
     return(CreateHttpResponse(message, () => {
         HttpResponseMessage reponse = null;
         if (ModelState.IsValid)
         {
             Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
         }
         else
         {
             _postCategoryService.Update(postCategory);
             _postCategoryService.SaveChanges();
             reponse = message.CreateResponse(HttpStatusCode.OK);
         }
         return reponse;
     }));
 }
Ejemplo n.º 5
0
 public static void UpdatePostCategory(this PostCategory postCategory, PostCategoryViewModel postCategoryVM)
 {
     postCategory.ID              = postCategoryVM.ID;
     postCategory.Name            = postCategoryVM.Name;
     postCategory.Alias           = postCategoryVM.Alias;
     postCategory.Description     = postCategoryVM.Description;
     postCategory.ParentID        = postCategoryVM.ParentID;
     postCategory.DisplayOrder    = postCategoryVM.DisplayOrder;
     postCategory.Image           = postCategoryVM.Image;
     postCategory.CreatedDate     = postCategoryVM.CreatedDate;
     postCategory.CreatedBy       = postCategoryVM.CreatedBy;
     postCategory.UpdatedDate     = postCategoryVM.UpdatedDate;
     postCategory.UpdatedBy       = postCategoryVM.UpdatedBy;
     postCategory.MetaKeyword     = postCategoryVM.MetaKeyword;
     postCategory.MetaDescription = postCategoryVM.MetaDescription;
     postCategory.Status          = postCategoryVM.Status;
 }
Ejemplo n.º 6
0
        public void PostCategory_Repository_Create()
        {
            PostCategory category = new PostCategory();

            //Gán cho các trường not null
            category.Name   = "Test category";
            category.Alias  = "Test-category";
            category.Status = true;

            var result = objRepository.Add(category);

            unitOfWork.Commit();

            //Assert: Giá trị muốn so sánh giữa 2 đối tượng
            Assert.IsNotNull(result);
            Assert.AreEqual(3, result.ID);
        }
Ejemplo n.º 7
0
        public void PostCategory_Repository_Create()
        {
            PostCategory pc = new PostCategory();

            pc.Name  = "C# Cơ bản";
            pc.Alias = "c-co-ban";

            pc.Status      = true;
            pc.CreatedDate = DateTime.Now;

            var result = _postCategoryRepository.Add(pc);

            _unitOfWork.Commit();

            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.ID);
        }
Ejemplo n.º 8
0
        public HttpResponseMessage Put(HttpRequestMessage request, PostCategory postCategory)
        {
            HttpResponseMessage response = null;

            if (ModelState.IsValid)
            {
                request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }
            else
            {
                _postCategoryService.Update(postCategory);
                _postCategoryService.Save();

                response = request.CreateResponse(HttpStatusCode.OK);
            }
            return(response);
        }
Ejemplo n.º 9
0
        public void UpdateCategoryTests()
        {
            var builder = new DbContextOptionsBuilder <ApplicationDbContext>().UseInMemoryDatabase(Guid.NewGuid().ToString());

            applicationDbContext = new ApplicationDbContext(builder.Options, _configuration);
            repository           = new Repository <PostCategory>(applicationDbContext);
            postCategoryService  = new PostCategoryService(repository);
            postCategoryService.Add(new PostCategory()
            {
                Id = Guid.Parse("117f991d-1f09-4a02-9880-e8fb1bdf287d")
            });
            applicationDbContext.SaveChanges();
            PostCategory postCategory = applicationDbContext.PostCategories.SingleOrDefault(s => s.Id == Guid.Parse("117f991d-1f09-4a02-9880-e8fb1bdf287d"));

            postCategoryService.Update(postCategory);
            Assert.Equal(1, applicationDbContext.PostCategories.Count());
        }
Ejemplo n.º 10
0
        public void PostCategory_Repository_Create()
        {
            PostCategory category = new PostCategory();

            category.Name   = "Test category";
            category.Alias  = "Test-category";
            category.Status = true;

            var result = objRepository.Add(category);

            unitOfWork.Commit();

            var list = objRepository.GetAll().ToList();

            Assert.IsNotNull(result);
            Assert.AreEqual(1, list.Count);
        }
Ejemplo n.º 11
0
 public static void UpdatePostCategory(this PostCategory model, PostCategoryViewModel viewModel)
 {
     model.Alias           = viewModel.Alias;
     model.CreatedBy       = viewModel.CreatedBy;
     model.CreatedDate     = viewModel.CreatedDate;
     model.Description     = viewModel.Description;
     model.DisplayOrder    = viewModel.DisplayOrder;
     model.HomeFlag        = viewModel.HomeFlag;
     model.Id              = viewModel.Id;
     model.Image           = viewModel.Image;
     model.MetaDescription = viewModel.MetaDescription;
     model.MetaKeyword     = viewModel.MetaKeyword;
     model.Name            = viewModel.Name;
     model.Status          = viewModel.Status;
     model.UpdatedBy       = viewModel.UpdatedBy;
     model.UpdatedDate     = viewModel.UpdatedDate;
 }
Ejemplo n.º 12
0
        public HttpResponseMessage Post(HttpRequestMessage request, PostCategoryViewModel postCategoryViewModel)
        {
            return(CreateHttpResponse(request,
                                      () => {
                HttpResponseMessage response = null;
                // kiểm tra ngoại lệ của dữ liệu truyền vào
                if (ModelState.IsValid)
                {
                    // nếu có lỗi thì truyền lỗi đó vào bảng lỗi trong database
                    request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
                }
                else
                {
                    // không có lỗi sẽ dùng  Service để lưu đối tượng vào database


                    PostCategory newPostCategory = new PostCategory();
                    // bất cứ đối tượng tạo ở Model(Shop.Web) sử dụng phương thức thì giá trị của nó sẽ tự động đẩy sang Model(Shop.Model)
                    newPostCategory.UpdatePostCategory(postCategoryViewModel);
                    var category = _postCategoryService.Add(newPostCategory);

                    try
                    {
                        _postCategoryService.Save();
                    }
                    catch (DbEntityValidationException e)
                    {
                        foreach (var eve in e.EntityValidationErrors)
                        {
                            Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                              eve.Entry.Entity.GetType().Name, eve.Entry.State);
                            foreach (var ve in eve.ValidationErrors)
                            {
                                Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                                  ve.PropertyName, ve.ErrorMessage);
                            }
                        }
                        throw;
                    }

                    // trả về đối tượng đã dược lưu để xử lý
                    response = request.CreateResponse(HttpStatusCode.Created, category);
                }
                return response;
            }));
        }
Ejemplo n.º 13
0
        public async Task <IActionResult> Create(PostCategoryEditModel model)
        {
            if (this.ModelState.IsValid)
            {
                var postCategory = new PostCategory
                {
                    Name = model.Name
                };

                this.context.PostCategories.Add(postCategory);
                await this.context.SaveChangesAsync();

                return(this.RedirectToAction("Index"));
            }

            return(this.View(model));
        }
Ejemplo n.º 14
0
        public void PostCategory_Repository_Create()
        {
            PostCategory category = new PostCategory();

            category.Name         = "Test category";
            category.Alias        = "test-category";
            category.ParentID     = 0;
            category.DisplayOrder = 1;
            category.Status       = true;

            var result = objRepository.Add(category);

            unitOfWork.Commit();

            Assert.IsNotNull(result);
            Assert.AreEqual(4, result.ID);
        }
        public void PostCategory_Service_Create()
        {
            PostCategory category = new PostCategory();

            category.Name   = "Test";
            category.Alias  = "Test";
            category.Status = true;
            _mockRepository.Setup(m => m.Add(category)).Returns((PostCategory p) =>
            {
                p.ID = 1;
                return(p);
            });
            var result = _categoryService.Add(category);

            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.ID);
        }
Ejemplo n.º 16
0
        public void PostCategory_Service_Add()
        {
            PostCategory pc = new PostCategory()
            {
                ID = 2, Name = "postcategory1", Alias = "post-category-1", Description = "", Status = true
            };

            _mockPostCategoryRepository.Setup(m => m.Add(pc)).Returns((PostCategory p) => {
                p.ID = 2;
                return(p);
            });

            var result = _postCategoryService.Add(pc);

            Assert.IsNotNull(result);
            Assert.AreEqual(2, result.ID);
        }
Ejemplo n.º 17
0
        public async Task <IActionResult> Edit(int id, [Bind("CategoryId,ParentId,Title,Content,Keyword,Slug,CoverUrl,Status")] PostCategory category)
        {
            if (id != category.CategoryId)
            {
                return(NotFound());
            }
            if (ModelState["Slug"].ValidationState == ModelValidationState.Invalid || string.IsNullOrEmpty(category.Slug))
            {
                category.Slug = string.IsNullOrEmpty(category.Slug) ? Utils.GenerateSlug(category.Title) : category.Slug;
                ModelState.SetModelValue("Slug", new ValueProviderResult(category.Slug));
                ModelState.Clear();
                TryValidateModel(category);
            }

            if (await _postService.IsSlugCategoryExisted(category.Slug, category.CategoryId))
            {
                ModelState.AddModelError(nameof(category.Slug), "Đường dẫn đã tồn tại");
            }
            if (ModelState.IsValid)
            {
                try
                {
                    await _postService.UpdateCategory(category);
                }
                catch (DbUpdateConcurrencyException ex)
                {
                    if (!await _postService.CategoryExists(category.CategoryId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            var listcategory = await _postService.GetAllCategory();

            listcategory.Insert(0, new PostCategory()
            {
                Title      = "Không có danh mục cha",
                CategoryId = -1
            });
            return(View(category));
        }
Ejemplo n.º 18
0
        public PostCategoryViewModel Add(PostCategoryViewModel model)
        {
            try
            {
                PostCategory postCategory = new PostCategory();
                postCategory.UpdatePostCategory(model);

                var res = _postCategoryService.Add(postCategory);
                _postCategoryService.SaveChanges();
                return(Mapper.Map <PostCategoryViewModel>(res));
            }
            catch (Exception ex)
            {
                LogError(ex);
                return(null);
            }
        }
        public async Task <PostCategory> UpdatePostCategory(PostCategory postCategory)
        {
            var result = await _appDbContext.PostCategories
                         .FirstOrDefaultAsync(p => p.PostCategoryId == postCategory.PostCategoryId);

            if (result != null)
            {
                result.Name = postCategory.Name;

                _appDbContext.Update(result);
                await _appDbContext.SaveChangesAsync();

                return(result);
            }

            return(result);
        }
        public HttpResponseMessage Post(HttpRequestMessage request, PostCategoryViewModel postCategoryVm)
        {
            return(CreateHttpResponse(request, () =>
            {
                HttpResponseMessage response = null;
                if (ModelState.IsValid)
                {
                    var postCategory = new PostCategory();
                    postCategory.UpdatePostCategory(postCategoryVm);
                    var category = _postCategoryService.Add(postCategory);
                    _postCategoryService.SaveChanges();

                    response = request.CreateResponse(HttpStatusCode.Created, category);
                }
                return response;
            }));
        }
Ejemplo n.º 21
0
        /// <summary>
        /// The CreatePostCategory
        /// </summary>
        /// <param name="pc">The obj<see cref="PostCategory"/></param>
        /// <param name="transaction">The transaction<see cref="TransactionalInformation"/></param>
        /// <returns>The <see cref="PostCategory"/></returns>
        public PostCategory CreatePostCategory(PostCategory pc, out TransactionalInformation transaction)
        {
            transaction = new TransactionalInformation();

            try
            {
                PostCategoryBusinessRules postCategoryBusinessRules = new PostCategoryBusinessRules();
                ValidationResult          results = postCategoryBusinessRules.Validate(pc);

                bool validationSucceeded           = results.IsValid;
                IList <ValidationFailure> failures = results.Errors;

                if (validationSucceeded == false)
                {
                    transaction = ValidationErrors.PopulateValidationErrors(failures);
                    return(pc);
                }

                // Begin session
                _dataService.CreateSession();

                var param = pc.ToDynamicParametersForInsert();

                _dataService.PostCategoryRepository.Insert(PostCategoryScript.Insert, param, CommandType.Text);

                pc.ID = param.Get <int>("@ID");

                _dataService.CommitTransaction(true);

                transaction.ReturnStatus = true;
                transaction.ReturnMessage.Add("successfully");
            }
            catch (Exception ex)
            {
                string errorMessage = ex.Message;
                transaction.ReturnMessage.Add(errorMessage);
                transaction.ReturnStatus = false;
            }
            finally
            {
                _dataService.CloseSession();
            }

            return(pc);
        }
Ejemplo n.º 22
0
 public static string Update(int ID, string Name, int ParentID)
 {
     using (var dbe = new inventorymanagementEntities())
     {
         PostCategory ui = dbe.PostCategories.Where(a => a.ID == ID).SingleOrDefault();
         if (ui != null)
         {
             ui.Name     = Name;
             ui.ParentID = ParentID;
             int kq = dbe.SaveChanges();
             return(kq.ToString());
         }
         else
         {
             return(null);
         }
     }
 }
Ejemplo n.º 23
0
        public PostCategory CreatePostCategory(PostCategory category)
        {
            category.Name = category.Name?.Trim();
            if (category.Name == null)
            {
                throw new Exception("Invalid category name");
            }

            var nameInUse = GetPostCategories().Where(c => c.Name == category.Name).Any();

            if (nameInUse)
            {
                throw new Exception("Category name already exists");
            }


            return(_aquariumDao.CreatePostCategory(category));
        }
        public void PostCategory_Repository_Create()
        {
            PostCategory obj = new PostCategory()
            {
                Name        = "post category test",
                Alias       = "post-category-test",
                CreatedDate = DateTime.Now,
                UpdatedDate = DateTime.Now,
                Status      = true
            };

            var result = objRepository.Add(obj);

            unitOfWork.Commit();

            Assert.IsNotNull(result);
            Assert.AreEqual(9, result.ID);
        }
Ejemplo n.º 25
0
        public void PostService_Create()
        {
            PostCategory ps = new PostCategory();
            int          id = 1;

            ps.Name   = "Name";
            ps.Alias  = "test 1";
            ps.Status = true;
            ///setup
            _mockRepository.Setup(p => p.Add(ps)).Returns((PostCategory p) => {
                p.ID = 1;
                return(p);
            });
            var resuilt = _categoryService.Add(ps);

            Assert.IsNotNull(resuilt);
            Assert.AreEqual(1, resuilt.ID);
        }
Ejemplo n.º 26
0
 public static void UpdatePostCategory(this PostCategory postCategory, PostCategoryViewModel postCategoryVM)
 {
     postCategory.PostCategoryID           = postCategoryVM.PostCategoryID;
     postCategory.PostCategoryName         = postCategoryVM.PostCategoryName;
     postCategory.PostCategoryAlias        = postCategoryVM.PostCategoryAlias;
     postCategory.PostCategoryDescription  = postCategoryVM.PostCategoryDescription;
     postCategory.PostCategoryParentID     = postCategoryVM.PostCategoryParentID;
     postCategory.PostCategoryDisplayOrder = postCategoryVM.PostCategoryDisplayOrder;
     postCategory.PostCategoryImage        = postCategoryVM.PostCategoryImage;
     postCategory.PostCategoryHomeFlag     = postCategoryVM.PostCategoryHomeFlag;
     postCategory.CreateDate      = postCategoryVM.CreateDate;
     postCategory.CreateBy        = postCategoryVM.CreateBy;
     postCategory.UpdateDate      = postCategoryVM.UpdateDate;
     postCategory.UpdateBy        = postCategoryVM.UpdateBy;
     postCategory.MetaKeyword     = postCategoryVM.MetaKeyword;
     postCategory.MetaDescription = postCategoryVM.MetaDescription;
     postCategory.Status          = postCategoryVM.Status;
 }
Ejemplo n.º 27
0
        [TransactionScopeAspect]//+++++
        public IResult Add(PostCategoryCreateDto postCategoryCreateDto)
        {
            var postCategory = new PostCategory
            {
                CategoryId = postCategoryCreateDto.CategoryId,
                PostId     = postCategoryCreateDto.PostId
            };

            var exist = PostCategoryExists(postCategory);

            if (exist.Success)
            {
                _postCategoryDal.MultipleAdd(postCategoryCreateDto);
            }
            //_postCategoryDal.Add(postCategory);

            return(new SuccessResult(Messages.CategoryAdded));
        }
Ejemplo n.º 28
0
        public static void UpdatepostCategory(this PostCategory postCategory,PostCategoryViewModel postCategoryVm)
        {
            postCategory.ID = postCategoryVm.ID;
            postCategory.Name = postCategoryVm.Name;
            postCategory.Description = postCategoryVm.Description;
            postCategory.Alias = postCategoryVm.Alias;
            postCategory.ParentID = postCategoryVm.ParentID;
            postCategory.DisplayOrder = postCategoryVm.DisplayOrder;
            postCategory.Image = postCategoryVm.Image;
            

            postCategory.CreatedDate = postCategoryVm.CreatedDate;
            postCategory.CreatedBy = postCategoryVm.CreatedBy;
            postCategory.UpdatedDate = postCategoryVm.UpdatedDate;
            postCategory.UpdatedBy = postCategoryVm.UpdatedBy;
         
            postCategory.Status = postCategoryVm.Status;
        }
Ejemplo n.º 29
0
 public static void UpdatePostCategory(this PostCategory postCategory, PostCategoryViewModel postCategoryVm)
 {
     postCategory.ID              = postCategoryVm.ID; // postCategoryVM là model còn cái kia là entity
     postCategory.Name            = postCategoryVm.Name;
     postCategory.Alias           = postCategoryVm.Alias;
     postCategory.ParentID        = postCategoryVm.ParentID;
     postCategory.DisplayOder     = postCategoryVm.DisplayOder;
     postCategory.Description     = postCategoryVm.Description;
     postCategory.Image           = postCategoryVm.Image;
     postCategory.HomeFlag        = postCategoryVm.HomeFlag;
     postCategory.CreatedDate     = postCategoryVm.CreatedDate;
     postCategory.CreatedBy       = postCategoryVm.CreatedBy;
     postCategory.UpdatedBy       = postCategoryVm.UpdatedBy;
     postCategory.UpdatedTime     = postCategoryVm.UpdatedTime;
     postCategory.MetaKeyword     = postCategoryVm.MetaKeyword;
     postCategory.MetaDescription = postCategoryVm.MetaDescription;
     postCategory.Status          = postCategoryVm.Status;
 }
 public static void UpdatePostCategory(this PostCategory postCategory, PostCategoryViewModel postCategoryVm)
 {
     postCategory.ID              = postCategoryVm.ID;
     postCategory.Name            = postCategoryVm.Name;
     postCategory.Alias           = postCategoryVm.Alias;
     postCategory.ParentID        = postCategoryVm.ParentID;
     postCategory.Decription      = postCategoryVm.Decription;
     postCategory.DisplayOrder    = postCategoryVm.DisplayOrder;
     postCategory.Image           = postCategoryVm.Image;
     postCategory.HomeFlag        = postCategoryVm.HomeFlag;
     postCategory.CreatedDate     = postCategoryVm.CreatedDate;
     postCategory.CreadedBy       = postCategoryVm.CreadedBy;
     postCategory.UpdateDate      = postCategoryVm.UpdateDate;
     postCategory.UpdateBy        = postCategoryVm.UpdateBy;
     postCategory.MetaKeyWord     = postCategoryVm.MetaKeyWord;
     postCategory.MetaDescription = postCategoryVm.MetaDescription;
     postCategory.Status          = postCategoryVm.Status;
 }
        public void PostCategory_Service_Test_Create()
        {
            PostCategory category = new PostCategory();
            category.Name = "Test";
            category.Alias = "Test";
            category.status = true;

            //Setup mock
            _mockRepository.Setup(m => m.Add(category)).Returns((PostCategory p) =>
            {
                p.ID = 1;
                return p;
            });
            var result = _categoryService.Add(category);

            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.ID);
        }
        public void DetailByTitleTest()
        {
            var title = "Title";

            var postCategoryID = "TestPostCategoryID";

            var postCategory = new PostCategory();
            postCategory.ID = postCategoryID;


            _postCategoryRepositoryMock.Expect(r => r.GetByTitle(title)).Return(postCategory);


            var result = TestedController.DetailByTitle(title);


            VerifyViewResult(result, "Detail", typeof(PostCategory), postCategory);
        }
        public void SaveDeleteTest()
        {
            var postCategoryID = "TestPostCategoryID";

            var postCategory = new PostCategory();
            postCategory.ID = postCategoryID;


            _postCategoryRepositoryMock.Expect(r => r.Get(postCategoryID)).Return(postCategory);
            _postCategoryRepositoryMock.Expect(r => r.Delete(postCategory));
            _postCategoryRepositoryMock.Expect(r => r.SubmitChanges());


            var result = TestedController.SaveDelete(postCategoryID);


            VerifyRedirectToRouteResult(result, expectedAction: "Index");
        }
Ejemplo n.º 34
0
 public ActionResult AddCategoryToPost(PostViewModel model)
 {
     var post = _blogRepository.GetPostById(model.ID);
     var postCats = _blogRepository.GetPostCategories(post);
     List<string> pCatIds = new List<string>();
     foreach (var pCat in postCats)
     {
         pCatIds.Add(pCat.id);
     }
     var newCats = model.Categories.Where(x => x.Checked == true).ToList();
     List<string> nCatIds = new List<string>();
     foreach (var pCat in newCats)
     {
         nCatIds.Add(pCat.id);
     }
     if (!pCatIds.SequenceEqual(nCatIds))
     {
         foreach (var pCat in postCats)
         {
             _blogRepository.RemovePostCategories(model.ID, pCat.id);
         }
         foreach (var cat in model.Categories)
         {
             PostCategory postCategory = new PostCategory();
             if (cat.Checked == true)
             {
                 postCategory.PostId = model.ID;
                 postCategory.CategoryId = cat.id;
                 postCategory.Checked = true;
                 _blogRepository.AddPostCategories(postCategory);
             }
         }
         _blogRepository.Save();
     }
     return RedirectToAction("EditPost", new { slug = post.UrlSeo });
 }
 public void Create(PostCategory entity)
 {
     this.categories.Create(entity);
     this.categories.Save();
 }
 public void Update(PostCategory entity)
 {
     this.categories.Update(entity);
     this.categories.Save();
 }
 public void Delete(PostCategory entity)
 {
     this.categories.Delete(entity);
     this.categories.Save();
 }
        internal static void SeedPostCategories(EntertainmentSystemDbContext context)
        {
            if (context.PostCategories.Any())
            {
                return;
            }

            var category = new PostCategory
            {
                Name = "Unknown"
            };

            context.PostCategories.Add(category);
            context.SaveChanges();
        }
Ejemplo n.º 39
0
 public PostCategory Add(PostCategory postCategory)
 {
     return _postCategoryReponsitory.Add(postCategory);
 }
Ejemplo n.º 40
0
 public Post(PostCategory c, GameEntity s = null, GameEntity t = null, Component comp = null, int sl = 0)
 {
     category = c;
     sourceEntity = s;
     targetEntity = t;
     component = comp;
     slot = sl;
 }
Ejemplo n.º 41
0
 public void Update(PostCategory postCategory)
 {
     _postCategoryReponsitory.Update(postCategory);
 }
Ejemplo n.º 42
0
 public void AddPostCategories(PostCategory postCategory)
 {
     _context.PostCategories.Add(postCategory);
 }