Пример #1
0
        public IActionResult Delete(int id)
        {
            IActionResult ret    = null;
            Player        entity = null;

            try
            {
                using (var db = new AngularBasicDbContext())
                {
                    entity = db.Players.Find(id);
                    if (entity != null)
                    {
                        db.Players.Remove(entity);
                        db.SaveChanges();
                    }
                    ret = StatusCode(StatusCodes.Status200OK, true);
                }
            }
            catch (Exception ex)
            {
                ret = HandleException(ex, "Exception trying to delete player: " + id.ToString());
            }

            return(ret);
        }
Пример #2
0
        public IActionResult Post([FromBody] Player entity)
        {
            IActionResult ret = null;

            try
            {
                using (var db = new AngularBasicDbContext())
                {
                    if (entity != null)
                    {
                        db.Players.Add(entity);
                        db.SaveChanges();
                        ret = StatusCode(StatusCodes.Status201Created,
                                         entity);
                    }
                    else
                    {
                        ret = StatusCode(StatusCodes.Status400BadRequest, "Invalid object passed to POST method");
                    }
                }
            }
            catch (Exception ex)
            {
                ret = HandleException(ex, "Exception trying to insert a new player");
            }

            return(ret);
        }
Пример #3
0
        public IActionResult Put([FromBody] Player entity)
        {
            IActionResult ret = null;

            try
            {
                using (var db = new AngularBasicDbContext())
                {
                    if (entity != null)
                    {
                        db.Update(entity);
                        db.SaveChanges();
                        ret = StatusCode(StatusCodes.Status200OK, entity);
                    }
                    else
                    {
                        ret = StatusCode(StatusCodes.Status400BadRequest, "Invalid object passed to PUT method");
                    }
                }
            }
            catch (Exception ex)
            {
                ret = HandleException(ex, "Exception trying to update player: " + entity.Id.ToString());
            }

            return(ret);
        }