public IHttpActionResult Put(int id, [FromBody] MakerInterfaceModel value) { try { if (id <= 0) { return(BadRequest()); } var result = repository.ModifyMaker(id, value); if (result.Code != HttpStatusCode.OK) { return(Content(result.Code, ModelState.GetErrorsDelprefix("value"))); } var model = repository.GetMakerByIdForInterface(id); return(Ok(model.resultData)); } catch (Exception ex) { return(InternalServerError(ex)); } }
public RepositoryResult <MakerInterfaceModel> ModifyMaker(int makerId, MakerInterfaceModel modifiedMaker) { try { if (makerId <= 0) { return(new RepositoryResult <MakerInterfaceModel>(HttpStatusCode.BadRequest)); } using (DataContext dbContext = DataContext.Create()) using (DbContextTransaction tx = dbContext.Database.BeginTransaction(System.Data.IsolationLevel.Serializable)) { modifiedMaker.Id = makerId; var maker = dbContext.MakerModels.Where(m => m.Id == makerId).SingleOrDefault(); if (maker == null) { tx.Rollback(); return(new RepositoryResult <MakerInterfaceModel>(HttpStatusCode.NotFound)); } maker.Enabled = modifiedMaker.Enabled; dbContext.Entry(maker).State = EntityState.Modified; if (dbContext.SaveChanges() == 0) { tx.Rollback(); return(new RepositoryResult <MakerInterfaceModel>(HttpStatusCode.Conflict)); } tx.Commit(); return(new RepositoryResult <MakerInterfaceModel>(HttpStatusCode.OK)); } } catch (Exception ex) { throw ex; } }
public IHttpActionResult Post([FromBody] MakerInterfaceModel value) { return(StatusCode(HttpStatusCode.MethodNotAllowed)); }