public MainSection AddMainSection(CreateMainSectionBindingModel model)
        {
            var mainSection = this.Mapper.Map <MainSection>(model);

            this.DbContext.MainSections.Add(mainSection);
            this.DbContext.SaveChanges();

            return(mainSection);
        }
Example #2
0
        public void AddMainSection_WithNullMainSection_ShouldThrowException()
        {
            // 1. Arrange
            CreateMainSectionBindingModel mainSectionModel = null;

            // 2. Act
            Action addMainSection = () => this.service.AddMainSection(mainSectionModel);

            // 3. Asserts
            Assert.ThrowsException <ArgumentNullException>(addMainSection);
        }
Example #3
0
        public void AddMainSection_WithPropeMainSection_ShouldAddOneMainSection()
        {
            // 1. Arrange
            var mainSectionModel = new CreateMainSectionBindingModel()
            {
                Name = MainSectionName,
            };

            // 2. Act
            this.service.AddMainSection(mainSectionModel);

            // 3. Asserts
            Assert.AreEqual(1, this.dbContext.MainSections.Count());
        }
Example #4
0
        public void AddMainSection_WithPropeрMainSection_ShouldAddCorrectly()
        {
            // 1. Arrange
            var mainSectionModel = new CreateMainSectionBindingModel()
            {
                Name = MainSectionName,
            };

            // 2. Act
            this.service.AddMainSection(mainSectionModel);

            // 3. Asserts
            var mainSection = this.dbContext.MainSections.First();

            Assert.AreEqual(MainSectionName, mainSection.Name);
        }
Example #5
0
        // [ValidateAntiForgeryToken]
        public IActionResult Create(CreateMainSectionBindingModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            var mainSection = this.adminSectionService.AddMainSection(model);

            this.TempData.Put("__Message", new MessageModel()
            {
                Type    = MessageType.Success,
                Message = WebConstants.MainSectionCreation
            });

            return(RedirectToAction("/"));
        }