// POST api/<controller> public void Post(SearchUrl searchUrl) { var userProfile = Context.Users.Include("Company").FirstOrDefault(x => x.UserId == User.Identity.Name); if (userProfile == null) return; searchUrl.CompanyId = userProfile.CompanyId; searchUrl.CreatedBy = User.Identity.Name; searchUrl.CreatedOn = DateTime.Now; searchUrl.ModifiedBy = User.Identity.Name; searchUrl.ModifiedOn = DateTime.Now; searchUrl.Active = true; Context.SearchUrls.AddOrUpdate(searchUrl); Context.SaveChanges(); }
// PUT api/<controller>/5 public void Put(int id, SearchUrl searchUrl) { var origSearchUrl = Context.SearchUrls.FirstOrDefault(x => x.Id == id); if (!searchUrl.Active) { if (origSearchUrl != null) { origSearchUrl.Active = false; origSearchUrl.ModifiedBy = User.Identity.Name; origSearchUrl.ModifiedOn = DateTime.Now; } } Context.SearchUrls.AddOrUpdate(origSearchUrl); Context.SaveChanges(); }