public ActionResult submitShifts([ModelBinder(typeof(ShiftBinder))] shifts obj) { if (Session["role"] != null) { //chackif got this shift if (ModelState.IsValid) { List <shifts> result = (from x in dal.WeekShifts where x.startDate == obj.startDate && x.userId == obj.userId select x).ToList <shifts>(); if (result.Count == 0) { dal.WeekShifts.Add(obj); dal.SaveChanges(); } else { User obj2 = new User(); ViewBag.eror = "alredy submited for the week"; return(View("_index", obj2)); } } } return(View("_index")); }
//added control only if loged in public ActionResult submitShifts([ModelBinder(typeof(ShiftBinder))] shifts obj) { if (Session["id"] != null) { //chackif got this shift if (ModelState.IsValid) { DateTime temp1 = DateTime.Parse(obj.startDate.Value.ToString()); int temp2 = obj.userId; List <shifts> result = (from x in dal.WeekShifts where x.startDate == temp1 && x.userId == temp2 select x).ToList <shifts>(); if (result.Count == 0) { dal.WeekShifts.Add(obj); dal.SaveChanges(); } else { ViewBag.eror = "alredy submited for the week"; return(View("_index")); } } return(View("_index")); } return(RedirectToAction("index", "home")); }
public static string newNurseShift(shifts shift) { string config = Convert.ToString(ConfigurationManager.ConnectionStrings["dbcon"]); List <shifts> shifts = new List <shifts>(); SqlConnection con = new SqlConnection(config); con.Open(); using (SqlCommand cmd = new SqlCommand("insert into Endoresment_Nurses_Shifts (Nurse_id,Nurse_name,Receive_from,Receive_name, Unit_id, Shift, Shift_date, Confirm, Entry_user) values(@Nurse_id, @Nurse_name,@Receive_from,@Receive_name,@Unit_id,@Shift,@Shift_date,@Confirm, @Entry_user) SELECT CAST(scope_identity() AS int)", con)) { cmd.Parameters.Add("@Nurse_id", SqlDbType.Int).Value = shift.Nurse_id; cmd.Parameters.Add("@Nurse_name", SqlDbType.VarChar).Value = shift.Nurse_name; cmd.Parameters.Add("@Receive_from", SqlDbType.Int).Value = shift.Receive_from; cmd.Parameters.Add("@Receive_name", SqlDbType.VarChar).Value = shift.Receive_name; cmd.Parameters.Add("@Unit_id", SqlDbType.Int).Value = shift.Unit_id; cmd.Parameters.Add("@Shift", SqlDbType.VarChar).Value = shift.Shift; cmd.Parameters.Add("@Shift_date", SqlDbType.VarChar).Value = shift.Shift_date; cmd.Parameters.Add("@Confirm", SqlDbType.Int).Value = shift.Confirm; cmd.Parameters.Add("@Entry_user", SqlDbType.Int).Value = shift.Entry_user; NewId = (Int32)cmd.ExecuteScalar(); } con.Close(); return(JsonConvert.SerializeObject(NewId)); }
public ActionResult AddShift(shifts sh) { if (Session["UserBL"] != null && ((UserBL)Session["UserBL"]).CheckActionCounter(0)) { shiftBL.Add(sh); return(RedirectToAction("ShiftsMenu")); } else { Session.Clear(); return(RedirectToAction("Index", "LogIn")); } }
public static string confirmShift(shifts shift) { string config = Convert.ToString(ConfigurationManager.ConnectionStrings["dbcon"]); List <shifts> shifts = new List <shifts>(); SqlConnection con = new SqlConnection(config); con.Open(); using (SqlCommand cmd = new SqlCommand("update Endoresment_Nurses_Shifts set Confirm = 1 where id = @id", con)) { cmd.Parameters.Add("@id", SqlDbType.Int).Value = shift.id; SqlDataReader idr = cmd.ExecuteReader(); } con.Close(); return(JsonConvert.SerializeObject(shifts)); }
public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) { HttpContextBase objcontex = controllerContext.HttpContext; string date = objcontex.Request.Form["date"]; int userId = 0; if (objcontex.Request.Form["userId"] != "" && objcontex.Request.Form["userId"] != null) { userId = int.Parse(objcontex.Request.Form["userId"]); } string su = objcontex.Request.Form["Sunday"]; string mo = objcontex.Request.Form["Monday"]; string tu = objcontex.Request.Form["Tuesday"]; string we = objcontex.Request.Form["Wensday"]; string th = objcontex.Request.Form["Thursday"]; string fr = objcontex.Request.Form["Friday"]; string sa = objcontex.Request.Form["Saturday"]; if (date == "") { date = DateTime.Today.ToString(); } DateTime parsedDate = DateTime.Parse(date); int start = (int)parsedDate.DayOfWeek; int target = (int)DayOfWeek.Sunday; if (target <= start) { target += 7; } DateTime nextS = parsedDate.AddDays(target - start); CultureInfo myCI = new CultureInfo("en-US"); Calendar myCal = myCI.Calendar; CalendarWeekRule myCWR = myCI.DateTimeFormat.CalendarWeekRule; DayOfWeek myFirstDOW = myCI.DateTimeFormat.FirstDayOfWeek; DateTime LastDay = nextS; int weeknum = myCal.GetWeekOfYear(LastDay, myCWR, myFirstDOW); List <shifts.shift> shiftlist = new List <shifts.shift>(); shiftlist.Add(new shifts.shift() { date = (nextS.AddDays(0)).ToString(), shiftChose = su }); shiftlist.Add(new shifts.shift() { date = (nextS.AddDays(1)).ToString(), shiftChose = mo }); shiftlist.Add(new shifts.shift() { date = (nextS.AddDays(2)).ToString(), shiftChose = tu }); shiftlist.Add(new shifts.shift() { date = (nextS.AddDays(3)).ToString(), shiftChose = we }); shiftlist.Add(new shifts.shift() { date = (nextS.AddDays(4)).ToString(), shiftChose = th }); shiftlist.Add(new shifts.shift() { date = (nextS.AddDays(5)).ToString(), shiftChose = fr }); shiftlist.Add(new shifts.shift() { date = (nextS.AddDays(6)).ToString(), shiftChose = sa }); shifts obj = new shifts() { startDate = nextS, year = nextS.Year, userId = userId, week = weeknum, shiftList = shiftlist }; return(obj); }