Exemple #1
0
 private void CheckActorForDuplication(CreateActorBindingModel model)
 {
     if (this.Data.Actors.All().Any(a => a.Name == model.Name))
     {
         throw new InvalidOperationException($"There is already actor with name {model.Name}");
     }
 }
Exemple #2
0
        public void CreateActor(CreateActorBindingModel model)
        {
            this.CheckModelForNull(model);
            this.CheckActorForDuplication(model);

            var actor = Mapper.Map <Actor>(model);

            this.Data.Actors.Add(actor);
            this.Data.SaveChanges();
        }
Exemple #3
0
        public void CreateActor_ValidModelState_ShouldCreateIt_AndRedirect()
        {
            var fakeUser = this.mocks.UserRepositoryMock.Object.All().FirstOrDefault(u => u.Id == "12345");

            this.CheckUserCredentials(fakeUser);

            var newActor = new CreateActorBindingModel()
            {
                Name        = null,
                Photo       = "New Actor Photo",
                IMDBProfile = "New Actor Profile"
            };

            this.controller.WithCallTo(c => c.Create(newActor)).ShouldRedirectToRoute("");
        }
Exemple #4
0
        public void CreateActor_InvalidModelState_ShouldReturnSameViewWithModel()
        {
            var fakeUser = this.mocks.UserRepositoryMock.Object.All().FirstOrDefault(u => u.Id == "12345");

            this.CheckUserCredentials(fakeUser);

            var newActor = new CreateActorBindingModel()
            {
                Name        = null,
                Photo       = "New Actor Photo",
                IMDBProfile = "New Actor Profile"
            };

            this.controller.ModelState.AddModelError("err", "name cannot be null");
            this.controller.WithCallTo(c => c.Create(newActor)).ShouldRenderDefaultView()
            .WithModel <CreateActorBindingModel>();
        }
        public ActionResult Create(CreateActorBindingModel model)
        {
            if (this.ModelState.IsValid)
            {
                try
                {
                    this.actorsService.CreateActor(model);
                    this.AddNotification("Created successfully", NotificationType.SUCCESS);
                    return(RedirectToAction("Index", "Actors", new { Area = "" }));
                }
                catch (Exception ex)
                {
                    this.AddNotification(ex.Message, NotificationType.ERROR);
                    return(this.View(model));
                }
            }

            return(this.View(model));
        }