public JsonResult BeginTask(WorkScheduleModel Data, string selectedKeys) { var innerEx = string.Empty; var exMessage = string.Empty; try { Data.CreatedDate = DateTime.Now; Data.GeneratedBy = User.Identity.Name; int wid = scheduleRepo.AddSchedule(Data); if (wid > 0) { PUBLICKEY = Data.PublicKey; string[] userIDS = selectedKeys.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); if (scheduleRepo.SaveActors(wid, userIDS)) { foreach (var item in userIDS) { int userID = int.Parse(item); var user = userRepo.GetAllUsers().Where(x => x.UID == userID).FirstOrDefault(); if (user != null) { SendNotificationEmail(Data, user); } } return(Json(new { success = true, infoMessage = $"Schedule successfully started and notifications have been sent to actors for this schedule." })); } } } catch (Exception ex) { if (PUBLICKEY != string.Empty) { scheduleRepo.RollTransaction(PUBLICKEY); } innerEx = ex.InnerException != null ? ex.InnerException.InnerException != null ? $" {ex.InnerException.Message} {ex.InnerException.InnerException.Message}" : $" {ex.InnerException.Message}" : string.Empty; exMessage = ex.Message; } return(Json(new { success = -1, errorMessage = $"{errorMessage}<br/> <b>Error Detail</b><br/> Error Message: <b>{exMessage}</b> </br> Inner Exception Message:<b> {innerEx}</b>" })); }