public IActionResult Add(AddGenreViewModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    _genreService.Add(new GenreDTO()
                    {
                        Name = model.Name
                    });

                    _loggerService.LogInformation(CONTROLLER_NAME + LoggerConstants.ACTION_ADD, LoggerConstants.TYPE_POST, $"add genre name: {model.Name} successful", GetCurrentUserId());

                    return(RedirectToAction("Index"));
                }
                catch (ValidationException ex)
                {
                    _loggerService.LogWarning(CONTROLLER_NAME + LoggerConstants.ACTION_ADD, LoggerConstants.TYPE_POST, $"add genre name: {model.Name} error: {ex.Message}", GetCurrentUserId());

                    ModelState.AddModelError(ex.Property, ex.Message);
                }
            }

            return(View(model));
        }
Example #2
0
        public ActionResult Genre(int AlbumId)
        {
            var model = new AddGenreViewModel
            {
                AlbumId = AlbumId
            };

            return(View(model));
        }
Example #3
0
        public ActionResult Genre(AddGenreViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            var genre = _albumService.AddGenre(model.AlbumId, model.Name);

            return(RedirectToRoute("AlbumDetails", new { id = model.AlbumId }));
        }
Example #4
0
        internal string IsHasNullData(AddGenreViewModel model)
        {
            StringBuilder result = new StringBuilder();

            if (string.IsNullOrEmpty(model.Name) || string.IsNullOrWhiteSpace(model.Name) || model.Name.Length < 4)
            {
                result.Append("Името на жанра трябва да съдържа поне 3 символа!");
            }

            return(result.ToString().Trim());
        }
Example #5
0
        public AddGenreViewModel GetGenreDataById(string genreId)
        {
            var genre = this.context.Genres.FirstOrDefault(g => g.Id == genreId);
            var model = new AddGenreViewModel()
            {
                Id   = genre.Id,
                Name = genre.Name,
            };

            return(model);
        }
Example #6
0
 internal bool IsDublicated(AddGenreViewModel model)
 {
     try
     {
         Genre genre = this.context.Genres.FirstOrDefault(g => g.Name == model.Name && g.DeletedOn == null);
         return(genre == null ? false : true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
        public IActionResult AddGenre(AddGenreViewModel model)
        {
            var startUp = this.StartUp();

            if (startUp != null)
            {
                return(startUp);
            }

            this.ViewData["message"] = this.adminGenreService.AddGenre(model);
            return(this.View());
        }
 public IActionResult Add(AddGenreViewModel addGenreViewModel)
 {
     if (ModelState.IsValid)
     {
         Genre newGenre = new Genre {
             Name = addGenreViewModel.Name
         };
         _context.Genres.Add(newGenre);
         _context.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(addGenreViewModel));
 }
        public void AddGenreAction_InvalidModelState_RedisplaysView()
        {
            var controller = this.SetupController();
            controller.ModelState.AddModelError("error", "error");
            var viewModel = new AddGenreViewModel();

            var result = controller.AddGenre(viewModel);

            Assert.IsInstanceOfType(result, typeof(ViewResult));
            var viewResult = (ViewResult)result;
            Assert.IsInstanceOfType(viewResult.Model, typeof(AddGenreViewModel));
            Assert.IsNull(viewResult.ViewName);
        }
Example #10
0
        public ActionResult AddGenre(AddGenreViewModel genreViewModel)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.RedirectToAction <PanelController>(c => c.Index()));
            }

            var mappedGenre = this.mapper.Map <Genre>(genreViewModel);

            this.genreService.AddGenre(mappedGenre);

            return(this.RedirectToAction <GenresGridController>(c => c.Index()));
        }
        public IHttpActionResult AddGenreToInventory(AddGenreViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Invalid Model State"));
            }

            var genre = _mapper.Map <Genre>(viewModel);

            _inventoryService.AddGenre(genre);

            return(Ok());
        }
Example #12
0
        public IActionResult GenreEditing(AddGenreViewModel model, string id)
        {
            this.StartUp();
            model.Id = this.HttpContext.Session.GetString("editPlanId");
            var result = this.addGenreService.EditGenre(model, this.userId);

            this.ViewData["message"] = result["message"];
            if (result["message"].ToString().Contains("Успешно"))
            {
                return(this.Index());
            }

            this.TempData["editPlanId"] = model.Id;
            return(this.View("EditGenre", model));
        }
Example #13
0
        public void AddGenreToInventory_AddGenreViewModel_AddsGenreToDatabase()
        {
            var genre = new Genre {
                Id = Guid.NewGuid(), GenreId = Guid.NewGuid()
            };

            var viewModel = new AddGenreViewModel();

            _inventoryController.AddGenreToInventory(viewModel);

            var genres = _context.Genres.ToList();

            const int expected = 1;

            Assert.AreEqual(expected, genres.Count);
        }
        public string AddGenre(AddGenreViewModel model)
        {
            var checherGenre = this.context.Genres.FirstOrDefault(g => g.Name == model.GenreName);

            if (checherGenre == null)
            {
                Genre genre = new Genre()
                {
                    Name = model.GenreName,
                };
                this.context.Genres.Add(genre);
                return("Успершно добавяне на жанр!");
            }

            return("Този жанр вече съществува в базата данни!");
        }
        public void AddGenreAction_ReturnsRedirectResult()
        {
            var controller = this.SetupController();
            var viewModel = new AddGenreViewModel()
            {
                Name = "GenreName"
            };

            var result = controller.AddGenre(viewModel);

            Assert.IsInstanceOfType(result, typeof(RedirectToActionResult));
            var redirectResult = (RedirectToActionResult)result;
            Assert.AreEqual("Genres", redirectResult.ActionName);
            Assert.AreEqual("ManageGenres", redirectResult.ControllerName);

            Assert.IsNull(redirectResult.RouteValues);
        }
Example #16
0
        public void OnlyRedirect_WhenModelStateIsValid()
        {
            // Arrange
            var genreViewModel = new AddGenreViewModel()
            {
            };

            var validationContext =
                new System.ComponentModel.DataAnnotations.ValidationContext(genreViewModel, null, null);

            var results = new List <ValidationResult>();

            // Act
            var isModelValid = Validator.TryValidateObject(genreViewModel, validationContext, results);

            // Assert
            Assert.IsFalse(isModelValid);
        }
        public IActionResult Add(AddGenreViewModel addGenreViewModel)
        {
            if (ModelState.IsValid)
            {
                // Add the new cheese to my existing cheeses
                MovieGenre newGenre = new MovieGenre
                {
                    Genre = addGenreViewModel.Name
                };

                context.Genres.Add(newGenre);
                context.SaveChanges();

                return(Redirect("/Category")); //******needs to redirect to add entry page
            }

            return(View(addGenreViewModel));
        }
Example #18
0
        public IActionResult Add(AddGenreViewModel addGenreViewModel)
        {
            if (ModelState.IsValid)
            {
                // Add the new genre to my existing genres
                MovieGenre newGenre = new MovieGenre
                {
                    Genre = addGenreViewModel.Name
                };

                context.Genres.Add(newGenre);
                context.SaveChanges();

                return(Redirect("/Movie/Add"));
            }

            return(View(addGenreViewModel));
        }
Example #19
0
        public void CallAddMethodOfGenreService_WhenModelStateIsValid()
        {
            var genreServiceMock  = new Mock <IGenreService>();
            var movieServiceMock  = new Mock <IMovieService>();
            var personServiceMock = new Mock <IPersonService>();
            var fileConverterMock = new Mock <IFileConverter>();
            var mapperMock        = new Mock <IMapper>();

            var genreViewModel = new AddGenreViewModel()
            {
                Name = "Genre"
            };

            var genreDbModel = new Genre()
            {
                Name = genreViewModel.Name
            };

            var validationContext =
                new System.ComponentModel.DataAnnotations.ValidationContext(genreViewModel, null, null);

            var results = new List <ValidationResult>();

            var isModelValid = Validator.TryValidateObject(genreViewModel, validationContext, results);

            mapperMock.Setup(x => x.Map <Genre>(genreViewModel)).Returns(genreDbModel);

            var panelController = new PanelController(
                genreServiceMock.Object,
                movieServiceMock.Object,
                personServiceMock.Object,
                fileConverterMock.Object,
                mapperMock.Object);

            // Act
            panelController.AddGenre(genreViewModel);

            // Assert
            Assert.IsTrue(isModelValid);
            genreServiceMock.Verify(gs => gs.AddGenre(genreDbModel), Times.Once);
        }
Example #20
0
        public void NotCallAddMethodOfGenreService_WhenModelStateIsInvalid()
        {
            var genreServiceMock  = new Mock <IGenreService>();
            var movieServiceMock  = new Mock <IMovieService>();
            var personServiceMock = new Mock <IPersonService>();
            var fileConverterMock = new Mock <IFileConverter>();
            var mapperMock        = new Mock <IMapper>();

            var genreViewModel = new AddGenreViewModel()
            {
            };

            var genreDbModel = new Genre()
            {
            };

            var validationContext =
                new System.ComponentModel.DataAnnotations.ValidationContext(genreViewModel, null, null);

            var results = new List <ValidationResult>();

            var isModelValid = Validator.TryValidateObject(genreViewModel, validationContext, results);

            var panelController = new PanelController(
                genreServiceMock.Object,
                movieServiceMock.Object,
                personServiceMock.Object,
                fileConverterMock.Object,
                mapperMock.Object);

            panelController.ModelState.AddModelError("name", "No genre name!");

            // Act
            panelController.AddGenre(genreViewModel);

            // Assert
            Assert.IsFalse(isModelValid);
            genreServiceMock.Verify(gs => gs.AddGenre(genreDbModel), Times.Never);
        }
Example #21
0
        public Dictionary <string, object> EditGenre(AddGenreViewModel model, string userId)
        {
            var result  = new Dictionary <string, object>();
            var message = this.IsHasNullData(model);

            if (string.IsNullOrEmpty(message))
            {
                message = "Жанра се дублира с друг!";
                if (this.IsDublicated(model) == false)
                {
                    var genre = this.context.Genres.FirstOrDefault(g => g.Id == model.Id);
                    genre.Name = model.Name;
                    this.context.SaveChanges();
                    message = "Успешно редактиран жанр!";
                    this.messageService.AddNotificationAtDB(userId, message);
                }
            }

            result.Add("model", model);
            result.Add("message", message);
            return(result);
        }
        public IActionResult AddGenre(AddGenreViewModel vM)
        {
            var genres = this.genreService.GetAll();

            foreach (var g in genres)
            {
                if (g.Name.Equals(vM.Name, StringComparison.InvariantCultureIgnoreCase))
                {
                    ViewData["GenreExists"] = "A genre with this name already exists!";
                    return(View(vM));
                }
            }

            if (this.ModelState.IsValid)
            {
                this.genreService.AddGenre(vM.Name);

                return(RedirectToAction("Genres", "ManageGenres"));
            }

            return(View(vM));
        }
Example #23
0
        public string AddGenre(AddGenreViewModel model, string userId)
        {
            var message = this.IsHasNullData(model);

            if (string.IsNullOrEmpty(message))
            {
                message = "Жанра се дублира с друг!";
                if (this.IsDublicated(model) == false)
                {
                    var genre = new Genre()
                    {
                        Name = model.Name,
                    };

                    this.context.Genres.Add(genre);
                    this.context.SaveChanges();

                    message = "Успешно добавен жанр!";
                    this.messageService.AddNotificationAtDB(userId, message);
                }
            }

            return(message);
        }
Example #24
0
        public AddGenreViewModel PreparedAddGenrePage()
        {
            var model = new AddGenreViewModel();

            return(model);
        }
        public IActionResult Add()
        {
            AddGenreViewModel addGenreViewModel = new AddGenreViewModel();

            return(View(addGenreViewModel));
        }
 public IActionResult AddGenre(AddGenreViewModel model)
 {
     this.StartUp();
     this.ViewData["message"] = this.addGenreService.AddGenre(model, this.userId);
     return(this.View("Index", model));
 }
Example #27
0
 public AddGenre()
 {
     InitializeComponent();
     DataContext = new AddGenreViewModel(this);
 }