// PUT: api/businessoffer/5 public IHttpActionResult Put(long?id, [FromBody] BusinessOfferServiceLocationViewModel model) { try { if (!id.HasValue) { return(Ok(new { status = false, data = "", message = "Please provide a valid ID." })); } if (model != null) { var businessOfferLocation = _db.tblBusinessOfferServiceLocations.Find(id.Value); if (businessOfferLocation != null) { businessOfferLocation.BusinessOfferId = model.BusinessOfferId; businessOfferLocation.ServiceLocationId = model.ServiceLocationId; _db.Entry(businessOfferLocation).State = EntityState.Modified; var response = _db.SaveChanges(); if (response > 0) { return(Ok(new { status = true, data = businessOfferLocation, message = "success" })); } else { return(Ok(new { status = false, data = "", message = "There was a problem to update the data." })); } } } return(Ok(new { status = false, data = "", message = "Not a valid data to update. Please provide a valid id." })); } catch (Exception ex) { return(Ok(new { status = false, data = "", message = "ex: " + ex.Message.ToString() })); } }
// POST: api/businessofferservicelocation public IHttpActionResult Post([FromBody] BusinessOfferServiceLocationViewModel model) { try { if (model != null) { var businessOfferLocation = new tblBusinessOfferServiceLocation() { BusinessOfferId = model.BusinessOfferId, ServiceLocationId = model.ServiceLocationId }; var check = _db.tblBusinessOfferServiceLocations.Where(d => d.BusinessOfferId == model.BusinessOfferId && d.ServiceLocationId == model.ServiceLocationId).ToList(); if (check.Count <= 0) { _db.tblBusinessOfferServiceLocations.Add(businessOfferLocation); var response = _db.SaveChanges(); if (response > 0) { return(Ok(new { status = true, data = businessOfferLocation, message = "success" })); } else { return(Ok(new { status = false, data = "", message = "There was a problem." })); } } else { return(Ok(new { status = false, data = "", message = "Offer has already linked with this offer. Try to link another location." })); } } else { return(Ok(new { status = false, data = "", message = "There was a problem." })); } } catch (Exception ex) { return(Ok(new { status = false, data = "", message = "ex: " + ex.Message.ToString() })); } }