public void insertFilePath(string filePath, int travelId) { var travelRequest = (from tr in _context.TravelRequests where tr.TravelId == travelId select tr).FirstOrDefault(); travelRequest.InvitationLetterPath = filePath; _context.SaveChanges(); }
//re-initializing all attributes because in future can give access to admin also to change sometravel details //public List<TravellingEmp> ApproveTravelRequest(int travelId, TravellingEmp approvedModel) //{ // List<TravellingEmp> updatedList = new List<TravellingEmp>(); // var record = _context.TravelRequests.SingleOrDefault(i => i.TravelId == travelId); // record.TravelRequestName = approvedModel.TravelRequestName; // record.TravelTypeId = (from tt in _context.TravelTypes // where tt.Type == approvedModel.Type // select tt.TravelTypeId).SingleOrDefault(); // record.StartDate = approvedModel.StartDate; // record.EndDate = approvedModel.EndDate; // record.Place = approvedModel.Place; // record.EmployeeId = (from e in _context.Employees // where e.EmployeeName == approvedModel.EmployeeName // select e.EmployeeId).SingleOrDefault(); // record.ClientId = (from c in _context.Clients // where c.ClientName == approvedModel.ClientName // select c.ClientId).SingleOrDefault(); // record.StatusId = (from s in _context.Statuses // where s.Message == approvedModel.Message // select s.StatusId).SingleOrDefault(); // record.TravelType = _context.TravelTypes.FirstOrDefault(i => i.TravelTypeId == record.TravelTypeId); // record.Employee = _context.Employees.FirstOrDefault(i => i.EmployeeId == record.EmployeeId); // record.Client = _context.Clients.FirstOrDefault(i => i.ClientId == record.ClientId); // record.Status = _context.Statuses.FirstOrDefault(i => i.StatusId == record.StatusId); // _context.SaveChanges(); // updatedList = this.ViewAllTravels(); // return updatedList; //} public List <TravelRequest> ApproveTravelRequest(int travelId, TravelRequest approvedModel) { List <TravelRequest> updatedList = new List <TravelRequest>(); var record = _context.TravelRequests.SingleOrDefault(i => i.TravelId == travelId); record.TravelRequestName = approvedModel.TravelRequestName; record.TravelTypeId = approvedModel.TravelTypeId; record.StartDate = approvedModel.StartDate; record.EndDate = approvedModel.EndDate; record.Place = approvedModel.Place; record.EmployeeProjectId = (from ep in _context.EmployeesProjects where ep.EmployeeId == approvedModel.EmployeeId && ep.ProjectId == approvedModel.ProjectId select ep.Id).FirstOrDefault(); record.ClientId = approvedModel.ClientId; record.StatusId = approvedModel.StatusId; record.TravelType = _context.TravelTypes.FirstOrDefault(i => i.TravelTypeId == record.TravelTypeId); record.Employee_Project = _context.EmployeesProjects.FirstOrDefault(i => i.Id == record.EmployeeProjectId); record.Client = _context.Clients.FirstOrDefault(i => i.ClientId == record.ClientId); record.Status = _context.Statuses.FirstOrDefault(i => i.StatusId == record.StatusId); _context.SaveChanges(); updatedList = this.ViewAllTravels(); return(updatedList); }
//manager public void insertTravelDetails(NewRequestViewModelOnSubmit outputModel) { using (var ctx = new da.KDTravelPortalDbContext()) { foreach (var tr in outputModel.travelRequests) { bool isClientFound = false; bool isTrvelTypeFound = false; bool isEmpWorkingUnderTheProject = false; bool isStatusfound = false; if (ctx.TravelTypes.Any(tt => tt.TravelTypeId == tr.TravelTypeId)) { isTrvelTypeFound = true; } else { throw new System.ArgumentException("This TravelType is not Found", "tr.TravelTypeId"); } if (ctx.Clients.Any(c => c.ClientId == tr.ClientId)) { isClientFound = true; } else { throw new System.ArgumentException("This Client is not Found", "tr.ClientId"); } if (ctx.Statuses.Any(s => s.StatusId == tr.StatusId)) { isStatusfound = true; } else { throw new System.ArgumentException("This status is not Found", "tr.StatusId"); } if (ctx.EmployeesProjects.Any(ep => ep.Id == (from x in ctx.EmployeesProjects where x.ProjectId == tr.ProjectId && x.EmployeeId == tr.EmployeeId select x.Id).FirstOrDefault())) { isEmpWorkingUnderTheProject = true; } else { throw new System.ArgumentException("tr.employeeId doesnt work under tr.projectId so you cannot assign a travel request for him for this project,kindly check the table EmployeesProject to know the employees and their respective Projects", ""); } if (isClientFound && isStatusfound && isTrvelTypeFound && isEmpWorkingUnderTheProject) { ctx.TravelRequests.Add(new da.TravelRequest() { TravelRequestName = tr.TravelRequestName, StartDate = tr.StartDate, EndDate = tr.EndDate, Place = tr.Place, TravelType = ctx.TravelTypes.FirstOrDefault(i => i.TravelTypeId == tr.TravelTypeId), TravelTypeId = tr.TravelTypeId, EmployeeProjectId = (from ep in ctx.EmployeesProjects where ep.ProjectId == tr.ProjectId && ep.EmployeeId == tr.EmployeeId select ep.Id).FirstOrDefault(), Employee_Project = ctx.EmployeesProjects.FirstOrDefault(i => i.Id == (from ep in ctx.EmployeesProjects where ep.ProjectId == tr.ProjectId && ep.EmployeeId == tr.EmployeeId select ep.Id).FirstOrDefault()), Client = ctx.Clients.FirstOrDefault(i => i.ClientId == tr.ClientId), ClientId = tr.ClientId, Status = ctx.Statuses.FirstOrDefault(i => i.StatusId == tr.StatusId), StatusId = tr.StatusId }); //TravelType t = ctx.TravelTypes.FirstOrDefault(i => i.TravelTypeId == tr.TravelTypeId); ctx.SaveChanges(); } else { throw new System.ArgumentException("Null value is being assigned chk all constrains", ""); } } } }