public async Task <IActionResult> Create(int bokingId) { var boking = await _context.TripBookings .Include(d => d.TripDelegates) .Include(e => e.SchedulingTripDetail.EducationalBody) .Include(t => t.SchedulingTripDetail.TripType) .Include(c => c.City) .FirstOrDefaultAsync(b => b.Id == bokingId); int duration = boking.TripQtyDays; if (boking.SchedulingTripDetail.TripType.Name == "عمرة") { duration += 2; } var delgations = await _context.TripDelegates.Where(e => e.TripBookingId == bokingId).ToListAsync(); var model = new List <LetterDelegationCreateModelView>(); foreach (var del in delgations) { var emps = new LetterDelegationCreateModelView() { EducationBody = boking.SchedulingTripDetail.EducationalBody.Name, Duration = duration, TripType = boking.SchedulingTripDetail.TripType.Name, FromCity = boking.SchedulingTripDetail.EducationalBody.City, ToCityName = boking.City.LocationName, TripDate = boking.SchedulingTripDetail.TripDate, BokingId = boking.Id, EmployeeName = del.EmployeeName, EmployeeNumber = del.EmployeeNumber, JopName = del.JopName, Confirmed = del.Confirmed, Id = del.Id }; model.Add(emps); } return(View(model)); }
public async Task <IActionResult> Create(int bokingId, List <LetterDelegationCreateModelView> employes) { if (ModelState.IsValid) { var letter = new Letter() { TripBookingId = employes[0].BokingId, TypeLetter = 3 }; _context.Letters.Add(letter); await _context.SaveChangesAsync(); var modelToSave = new List <TripDelegate>(); foreach (var del in employes) { var delForupdate = await _context.TripDelegates.FindAsync(del.Id); if (delForupdate != null) { delForupdate.Confirmed = del.Confirmed; modelToSave.Add(delForupdate); } } ; _context.UpdateRange(modelToSave); await _context.SaveChangesAsync(); return(RedirectToAction("IndexByBoking", "Letters", new { bokingId = bokingId })); } var boking = await _context.TripBookings .Include(d => d.TripDelegates) .Include(e => e.SchedulingTripDetail.EducationalBody) .Include(t => t.SchedulingTripDetail.TripType) .Include(c => c.City) .FirstOrDefaultAsync(b => b.Id == bokingId); int duration = boking.TripQtyDays; if (boking.SchedulingTripDetail.TripType.Name == "عمرة") { duration += 2; } var delgations = await _context.TripDelegates.Where(e => e.TripBookingId == bokingId).ToListAsync(); var model = new List <LetterDelegationCreateModelView>(); foreach (var del in delgations) { var emps = new LetterDelegationCreateModelView() { EducationBody = boking.SchedulingTripDetail.EducationalBody.Name, Duration = duration, TripType = boking.SchedulingTripDetail.TripType.Name, FromCity = boking.SchedulingTripDetail.EducationalBody.City, ToCityName = boking.City.LocationName, TripDate = boking.SchedulingTripDetail.TripDate, BokingId = boking.Id, EmployeeName = del.EmployeeName, EmployeeNumber = del.EmployeeNumber, JopName = del.JopName, Confirmed = del.Confirmed, Id = del.Id }; model.Add(emps); } return(View(model)); }