Exemple #1
0
        public IHttpActionResult PutVisit(int id, VisitContract visit)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != visit.ID)
            {
                return(BadRequest());
            }

            db.Entry(visit.ToInternal()).State = EntityState.Modified;

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
Exemple #2
0
        public IHttpActionResult PostVisit(VisitContract visit)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            Visit temp = visit.ToInternal();

            db.ResidentSet.Attach(temp.Resident);
            db.GuardSet.Attach(temp.Guard);
            db.DormitorySet.Attach(temp.Dormitory);
            db.GuestSet.Attach(temp.Guest);
            db.VisitSet.Add(temp);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException)
            {
                if (VisitExists(visit.ID))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtRoute("DefaultApi", new { id = visit.ID }, visit));
        }