public ActionResult EditSearchingFor(int?SearchingForID) { if (SearchingForID == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } SearchingFor searchingForObj = db.SearchingFors.Find(SearchingForID); if (searchingForObj == null) { return(HttpNotFound()); } return(PartialView(searchingForObj)); }
public JsonResult EditSearchingFor(int?SearchingForID, SearchingFor searchingForObj) { JsonResult result = new JsonResult(); if (ModelState.IsValid) { db.Entry(searchingForObj).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); result.Data = new { Success = true }; } else { result.Data = new { Success = false, Error = "Unable to save. Please enter valid values." }; } return(result); }
public JsonResult AddSearchingFor(SearchingFor wList) { JsonResult result = new JsonResult(); if (ModelState.IsValid) { using (db) { UserAccount usr = db.UserAccounts.Where(u => u.UserName.Equals(User.Identity.Name.ToString())).FirstOrDefault(); //Item Code var lastItem = db.SearchingFors.OrderByDescending(c => c.SearchingForID).FirstOrDefault(); if (lastItem == null) { wList.SearchingCode = "GB-SFC001"; } else { //using string substring method to get the number of the last inserted Item's ItemID wList.SearchingCode = "GB-SFC" + (Convert.ToInt32(lastItem.SearchingCode.Substring(6, lastItem.SearchingCode.Length - 6)) + 1).ToString("D3"); } //End of itemcode db.SearchingFors.Add(wList); UserSearchingFor usrList = new UserSearchingFor { UserID = usr.UserID, SearchingForID = wList.SearchingForID }; db.UserSearchingFors.Add(usrList); db.SaveChanges(); result.Data = new { Success = true }; } } else { result.Data = new { Success = false, Error = "Unable to save. Please enter valid values." }; } return(result); }