Пример #1
0
        // PUT api/LunchItem/5
        public async Task<IHttpActionResult> PutLunchItem(int id, LunchItem lunchitem)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

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

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

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!LunchItemExists(id))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return StatusCode(HttpStatusCode.NoContent);
        }
Пример #2
0
        public async Task<IHttpActionResult> PostLunchItem(LunchItem lunchitem)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            db.LunchItems.Add(lunchitem);
            await db.SaveChangesAsync();

            return CreatedAtRoute("DefaultApi", new { id = lunchitem.ID }, lunchitem);
        }
Пример #3
0
        public List<DailyLunch> GetWeekLunch(string date)
        {
            List<DailyLunch> list = new List<DailyLunch>();
            List<WorkingDay> week = WorkingDay.GetDays(date);
            week.RemoveAt(0);
            week.RemoveAt(5);

            foreach(WorkingDay day in week)
            {
                list.AddRange(db.DailyLunches.Where(i => i.LunchDate == day.Day));
            }

            foreach (DailyLunch d in list)
            {
                LunchItem curr = new LunchItem();
                d.LunchItem = db.LunchItems.Find(d.LunchItemId);
            }

            return list;
        }