public IActionResult PutOpportunity(int key, [FromBody] Models.Crm.Opportunity newItem) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (newItem == null || (newItem.Id != key)) { return(BadRequest()); } this.OnOpportunityUpdated(newItem); this.context.Opportunities.Update(newItem); this.context.SaveChanges(); var itemToReturn = this.context.Opportunities.Where(i => i.Id == key); Request.QueryString = Request.QueryString.Add("$expand", "Contact,OpportunityStatus"); return(new ObjectResult(SingleResult.Create(itemToReturn))); } catch (Exception ex) { ModelState.AddModelError("", ex.Message); return(BadRequest(ModelState)); } }
public IActionResult Post([FromBody] Models.Crm.Opportunity item) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (item == null) { return(BadRequest()); } this.OnOpportunityCreated(item); this.context.Opportunities.Add(item); this.context.SaveChanges(); var key = item.Id; var itemToReturn = this.context.Opportunities .Where(i => i.Id == key) .Include(i => i.Contact) .Include(i => i.OpportunityStatus) .FirstOrDefault(); return(new JsonResult(itemToReturn, new Newtonsoft.Json.JsonSerializerSettings { ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore, DateTimeZoneHandling = Newtonsoft.Json.DateTimeZoneHandling.Utc }) { StatusCode = 201 }); } catch (Exception ex) { ModelState.AddModelError("", ex.Message); return(BadRequest(ModelState)); } }
partial void OnOpportunityUpdated(Models.Crm.Opportunity item);
partial void OnOpportunityDeleted(Models.Crm.Opportunity item);