public object MakeAction(int id, Publication.STATE action) { using (CompraAppContext db = new CompraAppContext()) { Publication publicationForUpdate = db.Publications.Find(id); if (Exists(publicationForUpdate)) { if (checkAction(publicationForUpdate, action)) { if (action == Publication.STATE.CLOSE_BY_USER) { } publicationForUpdate.State = (int)action; db.Publications.Attach(publicationForUpdate); db.Entry(publicationForUpdate).State = EntityState.Modified; db.SaveChanges(); return(publicationForUpdate); } else { throw new Exception("Error: PublicaciĆ³n ya cerrada."); } } else { throw new Exception("Error: No existe la publicaciĆ³n."); } } }
private bool checkAction(Publication currentPublication, Publication.STATE action) { if (currentPublication.State == (int)Publication.STATE.OPEN) { return(true); } else { return(false); } }
public IHttpActionResult PostOfferAction(int id, Publication.STATE action) { try { return(Ok(publicationService.MakeAction(id, action))); } catch (Exception e) { return(BadRequest(e.Message)); } }