Beispiel #1
0
        public IHttpActionResult PutMenu(int id, Menu menu)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != menu.MenuId)
            {
                return BadRequest();
            }

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

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

            return StatusCode(HttpStatusCode.NoContent);
        }
Beispiel #2
0
        public IHttpActionResult PostMenu(Menu menu)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            try
            {

                menu.CreatedBy = ((ClaimsIdentity)User.Identity).GetUserId();
                menu.CreatedDate = DateTime.Now;
                menu.ModifiedBy = ((ClaimsIdentity)User.Identity).GetUserId();
                menu.ModifiedDate = DateTime.Now;
                menu.IsActive = true;
                menu.RestaurantId = ((ClaimsIdentity)User.Identity).GetUserId();

                db.Menus.Add(menu);
                db.SaveChanges();
            }
            catch (Exception e)
            {
                ErrorSignal.FromCurrentContext().Raise(e);
                throw new Exception("There was a problem saving this record: " + e.Message);

            }

            return CreatedAtRoute("DefaultApi", new { id = menu.MenuId }, menu);
        }