Example #1
0
        public IHttpActionResult Get(int id, [FromUri] BaseApiParameterModel param)
        {
            try
            {
                if (id <= 0)
                {
                    return(BadRequest(Messages.ApiIllegalParameter));
                }

                MakerApiModel result = dbContext.MakerModels.Where(x => x.Id == id)
                                       .ProjectTo <MakerApiModel>().SingleOrDefault();
                if (result == null)
                {
                    return(NotFound());
                }

                return(Ok(result));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
Example #2
0
        public IHttpActionResult Put(int id, [FromBody] MakerApiModel value)
        {
            try
            {
                if (id <= 0)
                {
                    return(BadRequest(Messages.ApiIllegalParameter));
                }

                using (DbContextTransaction tx =
                           dbContext.Database.BeginTransaction(System.Data.IsolationLevel.Serializable))
                {
                    value.Id = id;
                    MakerModel maker = dbContext.MakerModels.Where(m => m.Id == value.Id).SingleOrDefault();
                    if (maker == null)
                    {
                        tx.Rollback();
                        return(NotFound());
                    }

                    maker.Enabled = value.Enabled;
                    dbContext.Entry(maker).State = EntityState.Modified;
                    if (dbContext.SaveChanges() == 0)
                    {
                        tx.Rollback();
                        return(Conflict());
                    }

                    tx.Commit();
                    return(Ok(value));
                }
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
Example #3
0
 public IHttpActionResult Post([FromBody] MakerApiModel value)
 {
     return(StatusCode(HttpStatusCode.MethodNotAllowed));
 }