public void UpdateScheduleReportsStatus(ScheduleReportsPOSTparam postData) { string returnMessage = string.Empty; try { using (var db = new DBContext()) { if (ModelState.IsValid) { ScheduleReports model = new ScheduleReports(); model = db.ScheduleReports.AsNoTracking().First(p => p.ScreenId == postData.ScreenId && p.MembershipId == postData.MembershipId && p.ScheduleType == postData.sSheduleType); if (postData.sSheduleType == "D") { model.SendDate = model.SendDate.Value.AddDays(1); } else if (postData.sSheduleType == "W") { model.SendDate = model.SendDate.Value.AddDays(7); } else if (postData.sSheduleType == "M") { model.SendDate = model.SendDate.Value.AddMonths(1); } else if (postData.sSheduleType == "Q") { model.SendDate = model.SendDate.Value.AddMonths(3); } else if (postData.sSheduleType == "HY") { model.SendDate = model.SendDate.Value.AddMonths(6); } else if (postData.sSheduleType == "Y") { model.SendDate = model.SendDate.Value.AddYears(1); } db.Entry(model).State = EntityState.Modified; db.SaveChanges(); } } } catch (Exception e) { returnMessage = e.Message; ExceptionHandler handler = new ExceptionHandler(); handler.HandleException(e); } }
public ActionResult SaveScheduleReportPermission(string ScreensScheduleTypes) { try { //Check Authorization string roleName = System.Web.Security.Roles.GetRolesForUser().Single(); if (roleName.ToUpper() == "USER") { return(RedirectToAction("login", "account")); } using (var db = new DBContext()) { var schedulereports = (from u in db.ScheduleReports where u.MembershipId == WebSecurity.CurrentUserId select u).ToList(); foreach (var itm in schedulereports) { db.Entry(itm).State = EntityState.Deleted; db.SaveChanges(); } if (ScreensScheduleTypes != "") { string[] arrScreensSheduleTypes = ScreensScheduleTypes.Split('|'); foreach (var item in arrScreensSheduleTypes) { string[] arrScreensSheduleTypesNew = item.Split(','); int ScreenId = Convert.ToInt32(arrScreensSheduleTypesNew[0]); string ScheduleType = arrScreensSheduleTypesNew[1].ToString(); ScheduleReports model = new ScheduleReports(); model.ScreenId = ScreenId; model.MembershipId = WebSecurity.CurrentUserId; model.ScheduleType = ScheduleType; model.CreatedDate = DateTime.Now; model.SendDate = DateTime.Now; model.IsSend = false; model.CreatedBy = WebMatrix.WebData.WebSecurity.CurrentUserId; db.ScheduleReports.Add(model); db.SaveChanges(); } } } } catch (Exception e) { ExceptionHandler handler = new ExceptionHandler(); handler.HandleException(e); } return(RedirectToAction("Index")); }
public ActionResult SubmitSehedule(string modellist) { try { List <ScheduleReports> ModelData = JsonConvert.DeserializeObject <List <ScheduleReports> >(modellist); //// Check Authorization // string roleName = System.Web.Security.Roles.GetRolesForUser().Single(); // if (roleName.ToUpper() == "USER") // { // return RedirectToAction("login", "account"); // } using (var db = new DBContext()) { var schedulereports = (from u in db.ScheduleReports where u.MembershipId == WebSecurity.CurrentUserId select u).ToList(); foreach (var itm in schedulereports) { db.Entry(itm).State = EntityState.Deleted; db.SaveChanges(); } foreach (var item in ModelData) { ScheduleReports model = new ScheduleReports(); model.ScreenId = item.ScreenId; model.MembershipId = WebSecurity.CurrentUserId; model.ScheduleType = item.ScheduleType; model.CreatedDate = DateTime.Now; model.SendDate = DateTime.Now; model.IsSend = false; model.CreatedBy = WebMatrix.WebData.WebSecurity.CurrentUserId; db.ScheduleReports.Add(model); db.SaveChanges(); } } } catch (Exception e) { ExceptionHandler handler = new ExceptionHandler(); handler.HandleException(e); } return(RedirectToAction("Index")); }