Exemplo n.º 1
0
        public IHttpActionResult Post([FromBody] DiningRoomUse entity)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            entity.UserID = this.GetUserID();

            try
            {
                ServiceProvider.EntityContext.DiningRoomUse.Add(entity);
            }
            catch (DbUpdateException)
            {
                if (IsExists(entity.DiningRoomUseID))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }
            return(Ok(entity));
        }
Exemplo n.º 2
0
 public void Edit(DiningRoomUse entity)
 {
     using (var Context = GetContext())
     {
         Context.Entry(entity).State = EntityState.Modified;
         Context.SaveChanges();
     }
 }
Exemplo n.º 3
0
 public void Add(DiningRoomUse entity)
 {
     using (var Context = GetContext())
     {
         Context.DiningRoomUse.Add(entity);
         Context.SaveChanges();
     }
 }
Exemplo n.º 4
0
        public IHttpActionResult Get(int id)
        {
            DiningRoomUse entety = ServiceProvider.EntityContext.DiningRoomUse.Get(id);

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

            return(Ok(entety));
        }
Exemplo n.º 5
0
        public IHttpActionResult Delete([FromUri] int id)
        {
            DiningRoomUse entity = ServiceProvider.EntityContext.DiningRoomUse.Get(id);

            if (entity == null || entity.UserID != this.GetUserID())
            {
                return(NotFound());
            }

            ServiceProvider.EntityContext.DiningRoomUse.Remove(entity);

            return(Ok(entity));
        }
Exemplo n.º 6
0
        public IHttpActionResult Put([FromBody] DiningRoomUse entity)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            DiningRoomUse         existEntity         = null;
            IList <DiningRoomUse> existEntitiesByDate = ServiceProvider.EntityContext.DiningRoomUse.GetByDate(entity.Date, entity.Date.AddDays(1)).ToList();

            if (existEntitiesByDate != null && existEntitiesByDate.Count() > 0)
            {
                existEntity = existEntitiesByDate.FirstOrDefault(d => d.UserID == this.GetUserID());
            }



            try
            {
                if (existEntity == null)
                {
                    entity.UserID = this.GetUserID();
                    ServiceProvider.EntityContext.DiningRoomUse.Add(entity);
                }
                else
                {
                    existEntity.IsDiningRoomUse = entity.IsDiningRoomUse;
                    ServiceProvider.EntityContext.DiningRoomUse.Edit(existEntity);
                }
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!IsExists(entity.DiningRoomUseID))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(Ok(entity));
        }
Exemplo n.º 7
0
        public void Remove(DiningRoomUse entity)
        {
            using (var Context = GetContext())
            {
                var DiningRoomUse = Context.DiningRoomUse.FirstOrDefault(c => c.DiningRoomUseID == entity.DiningRoomUseID);

                if (DiningRoomUse != null)
                {
                    try
                    {
                        Context.DiningRoomUse.Remove(DiningRoomUse);
                        Context.SaveChanges();
                    }
                    catch (Exception)
                    {
                        throw;
                    }
                }
            }
        }