public async Task <ActionResult> updateWeek(oneWeek obj) { await Task.Run(() => { List <shifts> shiftFound = ( from x in dal.WeekShifts where x.userId.Equals(obj.WorkerId) select x).ToList <shifts>(); int serchValue = shiftFound[0].shiftsId; List <shifts.shift> week = ( from x in dal.Shifts1 where x.shiftsId.Equals(serchValue) select x).ToList <shifts.shift>(); week[0].shiftChose = obj.Sunday; week[1].shiftChose = obj.Monday; week[2].shiftChose = obj.Tuesday; week[3].shiftChose = obj.Wensday; week[4].shiftChose = obj.Thursday; week[5].shiftChose = obj.Friday; week[6].shiftChose = obj.Saturday; shiftFound[0].shiftList = week; dal.SaveChanges(); return(Json(new { data = "finised update worker" + obj.name, status = "success" })); }); return(Json(new { data = "sql eror conction", status = "fail" })); }
public ActionResult getOptions(string weeknum) { List <oneWeek> weekly = new List <oneWeek>(); //finds next sunday for the query int start = (int)new DateTime().DayOfWeek; int target = (int)DayOfWeek.Sunday; if (target <= start) { target += 7; } DateTime nextS = new DateTime().AddDays(target - start); //first find the currect week id with the user id List <tempData> result = (from x in dal.WeekShifts where x.week.Equals(3) select new tempData { weekId = (int)x.shiftsId, userId = (int)x.userId } ).ToList <tempData>(); string data = "<form><table class=\"table table-hover table - striped\"><tr>" + "<td>name</td>" + "<td>Sunday</td>" + "<td>Monday</td>" + "<td>Tuesday</td>" + "<td>Wensday</td>" + "<td>Thursday</td>" + "<td>Friday</td>" + "<td>Saturday</td>" + "</tr> "; //loop all weeks foreach (tempData y in result) { oneWeek temp = new oneWeek(); string oneperosn = "<tr>"; List <string> username = (from x in dal.users where x.userId.Equals(y.userId) select x.FirstName + " " + x.LastName ).ToList <string>(); if (username.Count > 0) { //test temp.name = username[0]; temp.WorkerId = y.userId; //add thr user name oneperosn += "<td>" + username[0] + "</td>"; } else { return(Content("problem with the user name")); } //add each shift List <string> shifts = (from x in dal.Shifts1 where x.shiftsId.Equals(y.weekId) select x.shiftChose ).ToList <string>(); //test temp.Sunday = shifts[0]; temp.Monday = shifts[1]; temp.Tuesday = shifts[2]; temp.Wensday = shifts[3]; temp.Thursday = shifts[4]; temp.Friday = shifts[5]; temp.Saturday = shifts[6]; weekly.Add(temp); foreach (string shiftsnum in shifts) { oneperosn += "<td>" + shiftsnum + "</td>"; } oneperosn += "</tr>"; data += oneperosn; } data += "</table></form>"; return(PartialView("_shiftsForNextWeek", weekly)); }