public RepositoryActionResult <FirmImage> Update(FirmImage t) { try { var existingData = _ctx.FirmImages.FirstOrDefault(exp => exp.Id == t.Id); if (existingData == null) { return(new RepositoryActionResult <FirmImage>(t, RepositoryActionStatus.NotFound)); } _ctx.Entry(existingData).State = EntityState.Detached; _ctx.FirmImages.Attach(t); _ctx.Entry(t).State = EntityState.Modified; var result = _ctx.SaveChanges(); if (result > 0) { return(new RepositoryActionResult <FirmImage>(t, RepositoryActionStatus.Updated)); } else { return(new RepositoryActionResult <FirmImage>(t, RepositoryActionStatus.NothingModified, null)); } } catch (Exception ex) { return(new RepositoryActionResult <FirmImage>(null, RepositoryActionStatus.Error, ex)); } }
public IHttpActionResult Post([FromBody] FirmImage firmImage) { try { if (firmImage == null) { return(BadRequest()); } var result = _repository.Insert(firmImage); if (result.Status == RepositoryActionStatus.Created) { // map to dto return(Created <FirmImage>(Request.RequestUri + "/" + firmImage.Id.ToString(), firmImage)); } return(BadRequest()); } catch (Exception) { return(InternalServerError()); } }
public RepositoryActionResult <FirmImage> Insert(FirmImage t) { try { _ctx.FirmImages.Add(t); var result = _ctx.SaveChanges(); if (result > 0) { return(new RepositoryActionResult <FirmImage>(t, RepositoryActionStatus.Created)); } else { return(new RepositoryActionResult <FirmImage>(t, RepositoryActionStatus.NothingModified, null)); } } catch (Exception ex) { return(new RepositoryActionResult <FirmImage>(null, RepositoryActionStatus.Error, ex)); } }