Example #1
0
        public IHttpActionResult PutDormitory(int id, DormitoryContract dormitory)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
Example #2
0
        public IHttpActionResult GetDormitory(int id)
        {
            DormitoryContract dormitory = db.DormitorySet.Find(id).ToContract();

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

            return(Ok(dormitory));
        }
Example #3
0
        public IHttpActionResult PostDormitory(DormitoryContract dormitory)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.DormitorySet.Add(dormitory.ToInternal());
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = dormitory.ID }, dormitory));
        }
Example #4
0
        public IHttpActionResult DeleteDormitory(int id)
        {
            DormitoryContract dormitory = db.DormitorySet.Find(id).ToContract();

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

            db.DormitorySet.Remove(dormitory.ToInternal());
            db.SaveChanges();

            return(Ok(dormitory));
        }
Example #5
0
        public static DormitoryInternal ToInternal(this DormitoryContract entity)
        {
            if (entity == null)
            {
                return(null);
            }

            var dorm = new DormitoryInternal
            {
                ID     = entity.ID,
                Adress = entity.Adress,
                Name   = entity.Name
            };

            return(dorm);
        }