public ActionResult Edit(PendingRequestModel pendingRequest) { if (ModelState.IsValid) { Save(pendingRequest); TempData["Message"] = "Changes saved"; return(RedirectToAction("Index")); } var model = new EditModel { PendingRequest = pendingRequest }; return(View(model)); }
public Result <List <PendingRequestModel> > AllPendingRequests(int S_id) { var result = new Result <List <PendingRequestModel> >(); result.Data = new List <PendingRequestModel>(); var Myposts = DbContext.Posts.Where(p => p.S_ID == S_id && p.isActive == 1).OrderByDescending(o => o.Post_Time).ToList(); try { foreach (var v in Myposts) { var PendingRequests = new PendingRequestModel(); PendingRequests.P_ID = v.P_ID; PendingRequests.description = v.Description; result.Data.Add(PendingRequests); } foreach (var v in result.Data) { var teachers = DbContext.Requests.Where(u => u.P_ID == v.P_ID).ToList(); v.TeacherList = new List <TeacherProfileModel>(); foreach (var v1 in teachers) { var UserInfo = DbContext.UserInfos.FirstOrDefault(u => u.ID == v1.T_ID); var teacher = DbContext.Teachers.FirstOrDefault(u => u.T_ID == v1.T_ID); var teacherProfileModel = new TeacherProfileModel(); try { teacherProfileModel.ContactNo = teacher.ContactNo; } catch (Exception ex) { teacherProfileModel.ContactNo = ""; } try { teacherProfileModel.Email = UserInfo.Email; } catch (Exception ex) { teacherProfileModel.Email = ""; } try { teacherProfileModel.Location = teacher.Location; } catch (Exception ex) { teacherProfileModel.Location = ""; } teacherProfileModel.Name = UserInfo.Name; v.TeacherList.Add(teacherProfileModel); } } } catch (Exception ex) { result.HasError = true; result.Message = ex.Message; } return(result); }
private void Save(PendingRequestModel pendingRequest) { PendingRequests.RemoveAll(pr => pr.Id == pendingRequest.Id); PendingRequests.Add(pendingRequest); }