public async Task <string> DeleteCabTypeAsync(long id) { try { utblMstCabType curObj = await db.utblMstCabTypes.FindAsync(id); db.utblMstCabTypes.Remove(curObj); await db.SaveChangesAsync(); return("Cab 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> SaveCabTypeAsync(utblMstCabType model) { try { if (model.CabTypeID == 0) { db.utblMstCabTypes.Add(model); await db.SaveChangesAsync(); return("New Cab Type Added"); } else { utblMstCabType curObj = await db.utblMstCabTypes.FindAsync(model.CabTypeID); curObj.CabTypeName = model.CabTypeName; curObj.CabTypeDesc = model.CabTypeDesc; curObj.BaseFare = model.BaseFare; await db.SaveChangesAsync(); return("Cab Type Details Updated"); } } catch (Exception ex) { return("Error : " + ex.Message); } }
public async Task <string> SaveCabType(utblMstCabType model) { if (ModelState.IsValid) { return(await objCab.SaveCabTypeAsync(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/cabtype"; utblMstCabType model = objAPI.GetObjectByKey <utblMstCabType>("cabconfig", "cabtypebyid", 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(utblMstCabType model) { try { ViewBag.ActiveURL = "/Admin/cabtype"; if (ModelState.IsValid) { string jsonStr = JsonConvert.SerializeObject(model); TempData["ErrMsg"] = objAPI.PostRecordtoApI("cabconfig", "savecabtype", jsonStr); return(RedirectToAction("index", "cabtype", new { Area = "Admin" })); } return(View(model)); } catch (AuthorizationException) { TempData["ErrMsg"] = "Your Login Session has expired. Please Login Again"; return(RedirectToAction("Login", "Account", new { Area = "" })); } }