public async Task <string> DeleteActivityAsync(long ActivityID) { try { utblMstActivitie curObj = await objDB.utblMstActivities.FindAsync(ActivityID); objDB.utblMstActivities.Remove(curObj); await objDB.SaveChangesAsync(); return("Activity 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 <utblMstActivitie> GetActivityByIDAsync(long id) { utblMstActivitie obj = new utblMstActivitie(); obj = await objDB.utblMstActivities.Where(x => x.ActivityID == id).FirstOrDefaultAsync(); return(obj); }
public async Task <string> SaveActivity(utblMstActivitie model) { if (ModelState.IsValid) { return(await objDal.SaveActivityAsync(model)); } string messages = string.Join("; ", ModelState.Values .SelectMany(x => x.Errors) .Select(x => x.ErrorMessage)); return("Operation Error: " + messages); }
public async Task <string> SaveActivityAsync(utblMstActivitie model) { try { var parAID = new SqlParameter("@ActivityID", model.ActivityID); var parAName = new SqlParameter("@ActivityName", model.ActivityName); var parADesc = new SqlParameter("@ActivityDesc", model.ActivityDesc); var parDestinationID = new SqlParameter("@DestinationID", model.DestinationID); var parBaseFare = new SqlParameter("@BaseFare", model.BaseFare); return(await objDB.Database.SqlQuery <string>("udspMstActivitiesAddEdit @ActivityID, @ActivityName,@ActivityDesc,@DestinationID,@BaseFare", parAID, parAName, parADesc, parDestinationID, parBaseFare).FirstOrDefaultAsync()); } catch (Exception ex) { return("Error: " + ex.Message); } }
public ActionResult EditActivity(long id) { try { utblMstActivitie modelapi = objAPI.GetObjectByKey <utblMstActivitie>("configuration", "activitybyid", id.ToString(), "id"); ActivityManageModel model = new ActivityManageModel(); model.Activity = new ActivitySaveModel() { ActivityID = modelapi.ActivityID, ActivityName = modelapi.ActivityName, ActivityDesc = modelapi.ActivityDesc, DestinationID = modelapi.DestinationID, BaseFare = modelapi.BaseFare }; model.Destinations = objAPI.GetAllRecords <utblMstDestination>("configuration", "alldestinations"); return(View(model)); } catch (AuthorizationException) { TempData["ErrMsg"] = "Your Login Session has expired. Please Login Again"; return(RedirectToAction("Login", "Account", new { Area = "" })); } }