Beispiel #1
0
 public void generateLetterOnDesig(int travelId, TravelRequest approvedTravel)
 {
     if (approvedTravel.StatusId == 2)
     {
         string templatePath = repo.getInvitationFormat(travelId, approvedTravel);
         if (templatePath != null)
         {
             string text = File.ReadAllText(templatePath, Encoding.UTF8);
             //keeep the feilds ready for thr file
             feilds = repo.getFeildsForInvitationLetter(approvedTravel);
             if (feilds != null)
             {
                 this.createFile(text, feilds);
             }
             else
             {
                 throw new System.ArgumentException("the feilds to be filled in the text file is null", "feilds:null");
             }
         }
         else
         {
             throw new System.ArgumentException(" NO InvitationTemplaten found for this designation check InvitationLetterFormatsTable In DB", "");
         }
     }
 }
        public InvitationLetterFeilds getFeildsForInvitationLetter(TravelRequest tr)
        {
            InvitationLetterFeilds feilds = new InvitationLetterFeilds();
            string empName;
            //get empprojId from EmployeesProjects table
            var EmpProjId = (from pe in _context.EmployeesProjects
                             where tr.EmployeeId == pe.EmployeeId &&
                             tr.ProjectId == pe.ProjectId
                             select pe.Id).FirstOrDefault();
            //check if that id exists in travel request table
            var isPresent = _context.TravelRequests.Any(i => i.EmployeeProjectId == EmpProjId);

            if (isPresent)
            {
                //first get emp id for te corresponsing EmpPrjId from EmployeesProjects table

                var empId = (from pe in _context.EmployeesProjects
                             where pe.Id == EmpProjId
                             select pe.EmployeeId).FirstOrDefault();
                //get the emp name for the corresponding empId from emp table
                empName = (from e in _context.Employees
                           where e.EmployeeId == empId
                           select e.EmployeeName).FirstOrDefault();
            }
            else
            {
                throw new System.ArgumentException("employeee not connected to the project check EmployeesProjectsTable", "");
            }

            var client = (from c in _context.Clients
                          where c.ClientId == tr.ClientId
                          select c.ClientName).FirstOrDefault();

            var project = (from p in _context.Projects
                           where p.ProjectId == tr.ProjectId
                           select p.ProjectName).FirstOrDefault();

            var managerId = (from p in _context.Projects
                             where p.ProjectId == tr.ProjectId
                             select p.InchargeId).FirstOrDefault();

            var managerName = (from e in _context.Employees
                               where e.EmployeeId == managerId
                               select e.EmployeeName).FirstOrDefault();

            feilds.EmployeeName = empName;
            feilds.StartDate    = tr.StartDate;
            feilds.EndDate      = tr.EndDate;
            feilds.Place        = tr.Place;
            feilds.ProjectName  = project;
            feilds.ClientName   = client;
            feilds.empId        = tr.EmployeeId;
            feilds.travelId     = tr.TravelId;
            feilds.travelName   = tr.TravelRequestName;
            feilds.managerName  = managerName;

            return(feilds);
        }
Beispiel #3
0
        public void createFile(string content, InvitationLetterFeilds feilds)
        {
            string fileName = feilds.travelName + feilds.empId.ToString() + feilds.travelId.ToString();
            string dirPath  = @"C:\kdtp\emp_invit_letters\";
            string filePath = $"{dirPath}" + fileName;

            if (!Directory.Exists(dirPath))
            {
                Directory.CreateDirectory(dirPath);
            }


            if (!File.Exists(filePath))
            {
                using (TextWriter tw = new StreamWriter(filePath))
                {
                    content = content.Replace("@name@", feilds.EmployeeName);
                    content = content.Replace("@place@", feilds.Place);
                    content = content.Replace("@project@", feilds.ProjectName);
                    content = content.Replace("@client@", feilds.ClientName);
                    content = content.Replace("@startdate@", feilds.StartDate.ToString());
                    content = content.Replace("@enddate@", feilds.EndDate.ToString());
                    content = content.Replace("@manager@", feilds.managerName);


                    tw.WriteLine(content);

                    this.insertFilePath(filePath, feilds.travelId);
                    tw.Close();
                }
            }
            else
            {
                throw new System.ArgumentException("file already exists", "fileName");
            }
        }