public async Task <IActionResult> Reject(long sid, long did) { DtoAMapping dtoAMapping = await _applicationDbContext.DtoAMappings.Where(d => d.StudentID == sid && d.DepartID == did).FirstOrDefaultAsync(); _applicationDbContext.DtoAMappings.Remove(dtoAMapping); await _applicationDbContext.SaveChangesAsync(); long id = did; return(RedirectToAction("Applications", new { id })); }
public async Task <IActionResult> ShowD([Bind("Did,Sid,Aid,Duty,Department,Enabled")] ShowDViewModel showDViewModel) { DtoAMapping dtoAMapping = await _applicationDbContext.DtoAMappings.Where(d => d.ApplicationID == showDViewModel.Aid && d.StudentID == showDViewModel.Sid).FirstOrDefaultAsync(); if (dtoAMapping == null) { return(NotFound()); } dtoAMapping.Enabled = showDViewModel.Enabled; dtoAMapping.Duty = showDViewModel.Duty; _applicationDbContext.DtoAMappings.Update(dtoAMapping); await _applicationDbContext.SaveChangesAsync(); long id = showDViewModel.Sid; return(RedirectToAction("Apply", new { id })); }
public IActionResult ShowD(long did, long sid, long aid) { ViewBag.id = sid; Depart depart = _applicationDbContext.Departs.Find(did); DtoAMapping dtoAMapping = _applicationDbContext.DtoAMappings.Where(d => d.ApplicationID == aid && d.StudentID == sid).FirstOrDefault(); ShowDViewModel showDViewModel = new ShowDViewModel { Sid = sid, Aid = aid, Did = did, Duty = "", Department = depart, Enabled = dtoAMapping.Enabled }; return(View(showDViewModel)); }
public async Task <IActionResult> Agree(long sid, long did) { DtoAMapping dtoAMapping = await _applicationDbContext.DtoAMappings.Where(d => d.StudentID == sid && d.DepartID == did).FirstOrDefaultAsync(); _applicationDbContext.DtoAMappings.Remove(dtoAMapping); await _applicationDbContext.SaveChangesAsync(); Depart depart = await _applicationDbContext.Departs.Where(d => d.ID == did).FirstOrDefaultAsync(); DtoMMapping dtoMMapping = new DtoMMapping { DepartID = did, MemberID = sid, Duty = dtoAMapping.Duty }; _applicationDbContext.DtoMMappings.Update(dtoMMapping); await _applicationDbContext.SaveChangesAsync(); long id = did; return(RedirectToAction("Applications", new { id })); }
public async Task <IActionResult> Apply(long id) { List <Application> applys = await _applicationDbContext.Applications.Where(a => a.Enabled == true).ToListAsync(); foreach (Application apply in applys) { if (apply.Blocktime < DateTime.Now) { apply.Enabled = false; } } _applicationDbContext.Applications.UpdateRange(applys); await _applicationDbContext.SaveChangesAsync(); ViewBag.id = id; Student stu = await _applicationDbContext.Students.SingleOrDefaultAsync(s => s.ID == id); if (stu == null) { return(NotFound()); } List <long> departids = await _applicationDbContext.DtoMMappings.Where(d => d.MemberID == id).Select(d => d.DepartID).ToListAsync(); List <Application> applications = new List <Application>(); if (departids.Count() != 0) { applications = await _applicationDbContext.Applications.Where(a => a.Grade == stu.Grade && a.Institute == stu.Institute && a.Enabled == true && (!(departids.Contains(a.DepartID)))).ToListAsync(); } else { applications = await _applicationDbContext.Applications.Where(a => a.Grade == stu.Grade && a.Institute == stu.Institute && a.Enabled == true).ToListAsync(); } if (applications == null) { return(NotFound()); } foreach (Application application in applications) { DtoAMapping dtoAMapping = await _applicationDbContext.DtoAMappings.Where(d => d.ApplicationID == application.ID && d.StudentID == id).FirstOrDefaultAsync(); if (dtoAMapping == null) { dtoAMapping = new DtoAMapping { ApplicationID = application.ID, DepartID = application.DepartID, StudentID = id, Duty = "", Enabled = false }; await _applicationDbContext.DtoAMappings.AddAsync(dtoAMapping); await _applicationDbContext.SaveChangesAsync(); } } List <ApplyViewModel> applyViewModels = new List <ApplyViewModel>(); for (int i = 0; i < applications.Count(); i++) { DtoAMapping dtoa = await _applicationDbContext.DtoAMappings.Where(d => d.ApplicationID == applications[i].ID && d.StudentID == id).FirstOrDefaultAsync(); ApplyViewModel applyviewmodel = new ApplyViewModel { DepartName = await _applicationDbContext.Departs.Where(d => d.ID == applications[i].DepartID).Select(d => d.Name).FirstOrDefaultAsync(), ApplicationID = applications[i].ID, Count = applications[i].Count, DepartID = applications[i].DepartID, Address = applications[i].Address, Duty = dtoa.Duty, Time = applications[i].Time, Enabled = dtoa.Enabled }; applyViewModels.Add(applyviewmodel); } return(View(applyViewModels)); }