Ejemplo n.º 1
0
        public void ADD_ShouldReturnDirectorAdded()
        {
            //Arrange
            int x        = 4;
            var director = new Director()
            {
                DirectorId = x, FirstName = "James", LastName = "Cameron", Age = 58, Rating = "9.6/10"
            };
            var options = new DbContextOptionsBuilder <CinemaDbContext>()
                          .UseInMemoryDatabase(databaseName: "ADD_ShouldReturnDirectorAdded")
                          .Options;

            var context = new CinemaDbContext(options);

            SeedDirectors(context);

            var service = new DirectorService(context);

            //Act
            var result = service.Add(director);


            //Assert
            Assert.True(result);
        }
 private void bSave_Click(object sender, EventArgs e)
 {
     try
     {
         if (string.IsNullOrWhiteSpace(tbName.Text))
         {
             MessageBox.Show(lName.Text + " cannot be empty!");
             return;
         }
         DirectorModel addDirectorModel = new DirectorModel();
         addDirectorModel.Name    = tbName.Text;
         addDirectorModel.Surname = tbSurname.Text;
         if (rbYes.Checked)
         {
             addDirectorModel.Retired = true;
         }
         else
         {
             addDirectorModel.Retired = false;
         }
         directorService.Add(addDirectorModel);
         ClearDirector();
         MessageBox.Show("Director added!");
     }
     catch (Exception exc)
     {
         throw exc;
     }
 }
Ejemplo n.º 3
0
        public IHttpActionResult Post([FromBody] DirectorCreateDto director)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }
                Director newDirector = new Director
                {
                    FirstName = director.FirstName,
                    LastName  = director.LastName,
                    City      = director.City
                };

                directorService.Add(newDirector);
                directorService.Save();

                var dtoDirector = new DirectorDto(newDirector);
                return(Ok(dtoDirector));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
Ejemplo n.º 4
0
        //[HandleError]
        //public ActionResult Create([Bind(Include = "Id,Name,Surname,Retired")] Director director)
        //public ActionResult Create([Bind(Include = "Name,Surname,Retired,MovieIds")] DirectorModel director)
        //public ActionResult Create([Bind(Exclude = "Id")] DirectorModel director)
        public ActionResult Create(DirectorModel director)
        {
            if (ModelState.IsValid)
            {
                //db.Directors.Add(director);
                //db.SaveChanges();
                directorService.Add(director);

                return(RedirectToAction("Index"));
            }

            return(View(director));
        }
 public void Add([FromBody] Director value)
 {
     _directorService.Add(value);
 }