public IHttpActionResult PutLandivar(int id, Landivar landivar)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != landivar.LandivarID)
            {
                return(BadRequest());
            }

            db.Entry(landivar).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!LandivarExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public ActionResult DeleteConfirmed(int id)
        {
            Landivar landivar = db.Landivars.Find(id);

            db.Landivars.Remove(landivar);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
 public ActionResult Edit([Bind(Include = "LandivarID,FriendofLandivar,Place,Email,Birthdate")] Landivar landivar)
 {
     if (ModelState.IsValid)
     {
         db.Entry(landivar).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(landivar));
 }
        public IHttpActionResult GetLandivar(int id)
        {
            Landivar landivar = db.Landivars.Find(id);

            if (landivar == null)
            {
                return(NotFound());
            }

            return(Ok(landivar));
        }
        public ActionResult Create([Bind(Include = "LandivarID,FriendofLandivar,Place,Email,Birthdate")] Landivar landivar)
        {
            if (ModelState.IsValid)
            {
                db.Landivars.Add(landivar);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(landivar));
        }
        public IHttpActionResult PostLandivar(Landivar landivar)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.Landivars.Add(landivar);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = landivar.LandivarID }, landivar));
        }
        public IHttpActionResult DeleteLandivar(int id)
        {
            Landivar landivar = db.Landivars.Find(id);

            if (landivar == null)
            {
                return(NotFound());
            }

            db.Landivars.Remove(landivar);
            db.SaveChanges();

            return(Ok(landivar));
        }
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Landivar landivar = db.Landivars.Find(id);

            if (landivar == null)
            {
                return(HttpNotFound());
            }
            return(View(landivar));
        }
예제 #9
0
        public void TestMethodDelete()
        {
            //Arrange
            LandivarsController landivarController = new LandivarsController();
            Landivar            landivar           = new Landivar()
            {
                LandivarID       = 1,
                FriendofLandivar = "Enrique",
                Place            = Places.Santa_Cruz,
                Email            = "*****@*****.**",
                Birthdate        = DateTime.Today
            };

            //Act
            IHttpActionResult actionResultPost   = landivarController.PostLandivar(landivar);
            IHttpActionResult actionResultDelete = landivarController.DeleteLandivar(landivar.LandivarID);

            //Assert
            Assert.IsInstanceOfType(actionResultDelete, typeof(OkNegotiatedContentResult <Landivar>));
        }
예제 #10
0
        public void TestMethodPost()
        {
            //Arrange
            LandivarsController landivarController = new LandivarsController();
            Landivar            Esperado           = new Landivar()
            {
                LandivarID       = 1,
                FriendofLandivar = "Pedro",
                Place            = Places.Santa_Cruz,
                Email            = "*****@*****.**",
                Birthdate        = DateTime.Today
            };

            //Act
            var Resultado = landivarController.PostLandivar(Esperado);
            var creado    = Resultado as CreatedAtRouteNegotiatedContentResult <Landivar>;

            //Assert
            Assert.IsNotNull(creado);
            Assert.AreEqual("DefaultApi", creado.RouteName);
            Assert.AreEqual(Esperado.FriendofLandivar, creado.Content.FriendofLandivar);
        }
예제 #11
0
        public void TestMethodPut()
        {
            //Arrange
            LandivarsController landivarController = new LandivarsController();
            Landivar            landivar           = new Landivar()
            {
                LandivarID       = 1,
                FriendofLandivar = "Victor",
                Place            = Places.Santa_Cruz,
                Email            = "*****@*****.**",
                Birthdate        = DateTime.Today
            };

            //Act
            IHttpActionResult actionResultPost = landivarController.PostLandivar(landivar);
            var result = landivarController.PutLandivar(landivar.LandivarID, landivar) as StatusCodeResult;


            //Assert
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(StatusCodeResult));
            Assert.AreEqual(HttpStatusCode.NoContent, result.StatusCode);
        }