public async Task <string> DeleteHotelTypeAsync(long id) { try { utblMstHotelType curObj = await db.utblMstHotelTypes.FindAsync(id); db.utblMstHotelTypes.Remove(curObj); await db.SaveChangesAsync(); return("Hotel Type Details Removed"); } catch (SqlException ex) { if (ex.Errors.Count > 0) // Assume the interesting stuff is in the first error { switch (ex.Errors[0].Number) { case 547: // Foreign Key violation return("This record has dependencies on other records, so cannot be removed."); default: return("Error: " + ex.Message); } } return("Error while operation. Error Message: " + ex.Message); } catch (Exception ex) { return("Error: " + ex.Message); } }
public async Task <string> SaveHotelTypeAsync(utblMstHotelType model) { try { if (model.HotelTypeID == 0) { db.utblMstHotelTypes.Add(model); await db.SaveChangesAsync(); return("New Hotel Type Added"); } else { utblMstHotelType curObj = await db.utblMstHotelTypes.FindAsync(model.HotelTypeID); curObj.HotelTypeName = model.HotelTypeName; curObj.BaseFare = model.BaseFare; await db.SaveChangesAsync(); return("Hotel Type Details Updated"); } } catch (Exception ex) { return("Error: " + ex.Message); } }
public async Task <string> SaveHotelType(utblMstHotelType model) { if (ModelState.IsValid) { return(await objHotel.SaveHotelTypeAsync(model)); } string messages = string.Join("; ", ModelState.Values .SelectMany(x => x.Errors) .Select(x => x.ErrorMessage)); return("Operation Error: " + messages); }
public ActionResult Edit(long id) { try { ViewBag.ActiveURL = "/Admin/hoteltype"; utblMstHotelType model = objAPI.GetObjectByKey <utblMstHotelType>("hotelconfig", "hoteltypebyid", id.ToString(), "id"); return(View(model)); } catch (AuthorizationException) { TempData["ErrMsg"] = "Your Login Session has expired. Please Login Again"; return(RedirectToAction("Login", "Account", new { Area = "" })); } }
public ActionResult Edit(utblMstHotelType model) { try { ViewBag.ActiveURL = "/Admin/hoteltype"; if (ModelState.IsValid) { string jsonStr = JsonConvert.SerializeObject(model); TempData["ErrMsg"] = objAPI.PostRecordtoApI("hotelconfig", "savehoteltype", jsonStr); return(RedirectToAction("index", "hoteltype", new { Area = "Admin" })); } return(View(model)); } catch (AuthorizationException) { TempData["ErrMsg"] = "Your Login Session has expired. Please Login Again"; return(RedirectToAction("Login", "Account", new { Area = "" })); } }