Ejemplo n.º 1
0
        public static void RejectMailToAdminAndEmployee(DeclarationFormModel decModel, string employeeName, string clientName)
        {
            //message components
            // mail naar Admin
            var message1 = new MimeMessage();                                           //naar admin

            message1.From.Add(new MailboxAddress("Qien", "*****@*****.**")); //aanpassen naar Admin mailadres
            message1.To.Add(new MailboxAddress("Liza", "*****@*****.**"));    //aanpassen naar Admin mailadres
            message1.Subject = $"Afgekeurd: Urendeclaratieformulier van {employeeName} voor de maand {decModel.Month}";
            message1.Body    = new TextPart("html")
            {
                Text = $"Beste Qien,<br><br>De opdrachtgever heeft het urendeclaratieformulier van {employeeName} voor de maand {decModel.Month} afgekeurd. <br> Wil je deze afkeuring bekijken en het urendeclaratieformulier weer heropenen voor {employeeName}? <br><br> Met vriendelijke groet,<br><br> Team Qien"
            };

            //mail naar Employee
            var message2 = new MimeMessage();                                           //naar employee als urendeclaratieformulier is afgekeurd --> nog doen als het heropent is??

            message2.From.Add(new MailboxAddress("Qien", "*****@*****.**")); //aanpassen naar Admin mailadres
            message2.To.Add(new MailboxAddress("Liza", "*****@*****.**"));    //aanpassen naar Employee mailadres
            message2.Subject = $"Afgekeurd: Urendeclaratieformulier voor de maand {decModel.Month}";
            message2.Body    = new TextPart("html")
            {
                Text = $"Beste {employeeName},<br><br>De opdrachtgever heeft jouw urendeclaratieformulier voor de maand {decModel.Month} afgekeurd. </br> Zodra deze weer beschikbaar is gesteld door Qien, kan je jouw urendeclaratieformulier opnieuw indienen.<br><br>Met vriendelijke groet,<br><br> Team Qien"
            };

            using (var client = new SmtpClient())
            {
                client.ServerCertificateValidationCallback = (s, c, h, e) => true;
                client.Connect("Smtp.gmail.com", 587, false);
                client.Authenticate("*****@*****.**", "Hans123!");
                client.Send(message1);
                client.Send(message2);
                client.Disconnect(true);
            }
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> MailService(DeclarationFormModel decModel, string uniqueId, string formId, string employeeName, IFormFile file)
        {
            employeeRepo.UploadFile(file, decModel.FormId);
            if (!await employeeRepo.UserIsEmployeeOrTrainee())
            {
                return(AccessDeniedView());
            }

            try
            {
                await declarationFormRepo.EditDeclarationForm(decModel);
            }
            catch (MoreThan24HoursException e)
            {
                return(RedirectToAction("HourReg", "DeclarationForm", new { declarationFormId = decModel.FormId, userId = decModel.EmployeeId, year = decModel.Year, month = decModel.Month, errorMessage = e.Message }));
            }

            await declarationFormRepo.SubmitDeclarationForm(decModel);

            await declarationFormRepo.CalculateTotalHours(decModel);

            //hier word mail opgesteld en verstuurd
            Mailservice.MailFormToClient(decModel, uniqueId, formId, employeeName);
            return(RedirectToRoute(new { controller = "Home", action = "Index" }));
        }
Ejemplo n.º 3
0
        public async Task EditDeclarationForm(DeclarationFormModel formModel)
        {
            var form = await context.DeclarationForms.SingleAsync(d => d.DeclarationFormId == formModel.FormId);

            var hourList = new List <HourRow>();

            foreach (var row in formModel.HourRows)
            {
                var entity = await context.HourRows.SingleAsync(h => h.HourRowId == row.HourRowId);

                entity.Worked           = row.Worked;
                entity.Overtime         = row.Overtime;
                entity.Sickness         = row.Sickness;
                entity.Vacation         = row.Vacation;
                entity.Holiday          = row.Holiday;
                entity.Training         = row.Training;
                entity.Other            = row.Other;
                entity.OtherExplanation = row.OtherExplanation;
                row.TotalRow            = row.Worked + row.Overtime + row.Sickness + row.Vacation + row.Holiday + row.Training + row.Other;

                if (row.TotalRow > 24)
                {
                    throw new MoreThan24HoursException();
                }
                else
                {
                    await context.SaveChangesAsync();
                }
            }
        }
Ejemplo n.º 4
0
        public static void MailFormToClient(DeclarationFormModel decModel, string uniqueId, string formId, string employeeName)
        {
            //message components
            var message = new MimeMessage();

            message.From.Add(new MailboxAddress("Hans", "*****@*****.**"));
            message.To.Add(new MailboxAddress("Liza", "*****@*****.**"));
            message.Subject = $"Urendeclaratieformulier van {employeeName} voor de maand {decModel.Month}";
            var link = "https://*****:*****@gmail.com", "Hans123!");
                client.Send(message);
                client.Disconnect(true);
            }
        }
Ejemplo n.º 5
0
        public async Task SubmitDeclarationForm(DeclarationFormModel formModel)
        {
            var form = await context.DeclarationForms.SingleAsync(d => d.DeclarationFormId == formModel.FormId);

            form.Submitted = true;
            form.Approved  = "Pending";
            await context.SaveChangesAsync();
        }
        public Task <List <DeclarationFormModel> > GetAllFormsOfUser(string userId)
        {
            var declarationFormModel = new DeclarationFormModel {
                EmployeeId = userId
            };
            var declarationFormList = new List <DeclarationFormModel>();

            declarationFormList.Add(declarationFormModel);
            return(Task.FromResult(declarationFormList));
        }
Ejemplo n.º 7
0
        public async Task <FileContentResult> DownloadExcel(int formId)
        {
            Download             download        = new Download();
            DeclarationFormModel declarationForm = await declarationFormRepo.GetForm(formId);

            download.MakeExcel(Convert.ToString(formId), declarationForm.HourRows);
            var fileName = Convert.ToString(formId) + ".xlsx";

            byte[] fileBytes = System.IO.File.ReadAllBytes("Downloads/" + fileName);
            return(File(fileBytes, "Application/x-msexcel", fileName));
        }
Ejemplo n.º 8
0
        public List <DeclarationFormModel> EntitiesToDeclarationFormModels(List <DeclarationForm> forms)
        {
            var declarationFormModels = new List <DeclarationFormModel>();

            foreach (var form in forms)
            {
                string month = "";
                if (MonthConverter.ConvertMonthToInt(form.Month) < 10)
                {
                    month = 0 + MonthConverter.ConvertMonthToInt(form.Month).ToString();
                }
                else
                {
                    month = MonthConverter.ConvertMonthToInt(form.Month).ToString();
                }
                string yearString      = form.Year.ToString();
                string monthYearString = yearString + month;
                int    monthYear       = Convert.ToInt32(monthYearString);

                var newModel = new DeclarationFormModel
                {
                    FormId           = form.DeclarationFormId,
                    EmployeeId       = form.EmployeeId,
                    Month            = form.Month,
                    Approved         = form.Approved,
                    Submitted        = form.Submitted,
                    Comment          = form.Comment,
                    Year             = form.Year,
                    monthyear        = monthYear,
                    uniqueId         = form.uniqueId,
                    TotalWorkedHours = form.TotalWorkedHours,
                    TotalOvertime    = form.TotalOvertime,
                    TotalSickness    = form.TotalSickness,
                    TotalVacation    = form.TotalVacation,
                    TotalHoliday     = form.TotalHoliday,
                    TotalTraining    = form.TotalTraining,
                    TotalOther       = form.TotalOther,
                    DateCreated      = form.DateCreated
                };
                declarationFormModels.Add(newModel);
            }

            return(declarationFormModels);
        }
Ejemplo n.º 9
0
        public async Task CalculateTotalHours(DeclarationFormModel decModel)
        {
            var declarationformEntity = await context.DeclarationForms.SingleAsync(df => df.DeclarationFormId == decModel.FormId);

            declarationformEntity.TotalWorkedHours = 0;
            declarationformEntity.TotalOvertime    = 0;
            declarationformEntity.TotalSickness    = 0;
            declarationformEntity.TotalVacation    = 0;
            declarationformEntity.TotalHoliday     = 0;
            declarationformEntity.TotalTraining    = 0;
            declarationformEntity.TotalOther       = 0;
            foreach (var HourRow in decModel.HourRows)
            {
                declarationformEntity.TotalWorkedHours += HourRow.Worked;
                declarationformEntity.TotalOvertime    += HourRow.Overtime;
                declarationformEntity.TotalSickness    += HourRow.Sickness;
                declarationformEntity.TotalVacation    += HourRow.Vacation;
                declarationformEntity.TotalHoliday     += HourRow.Holiday;
                declarationformEntity.TotalTraining    += HourRow.Training;
                declarationformEntity.TotalOther       += HourRow.Other;
            }
            await context.SaveChangesAsync();
        }
Ejemplo n.º 10
0
        public async Task <IActionResult> HourReg(DeclarationFormModel decModel, IFormFile file)
        {
            if (await employeeRepo.UserIsEmployeeOrTrainee())
            {
                employeeRepo.UploadFile(file, decModel.FormId);

                try
                {
                    await declarationRepo.EditDeclarationForm(decModel);
                }
                catch (MoreThan24HoursException e)
                {
                    return(RedirectToAction("HourReg", new { declarationFormId = decModel.FormId, userId = decModel.EmployeeId, year = decModel.Year, month = decModel.Month, errorMessage = e.Message }));
                }

                await declarationRepo.CalculateTotalHours(decModel);

                return(RedirectToAction("Dashboard", "Employee"));
            }
            else
            {
                return(AccessDeniedView());
            }
        }
 public Task EditDeclarationForm(DeclarationFormModel formModel)
 {
     throw new NotImplementedException();
 }
 public Task CalculateTotalHours(DeclarationFormModel decModel)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 13
0
        public DeclarationFormModel GetFormNotAsync(int formId)
        {
            var entity = context.DeclarationForms.Include(df => df.HourRows).Single(d => d.DeclarationFormId == formId);

            List <HourRowModel> ListOfHourRowModels = new List <HourRowModel>();

            foreach (HourRow hourRow in entity.HourRows)
            {
                HourRowModel newHourRowModel = new HourRowModel
                {
                    HourRowId        = hourRow.HourRowId,
                    EmployeeId       = entity.EmployeeId,
                    Date             = hourRow.Date,
                    Worked           = hourRow.Worked,
                    Overtime         = hourRow.Overtime,
                    Sickness         = hourRow.Sickness,
                    Vacation         = hourRow.Vacation,
                    Holiday          = hourRow.Holiday,
                    Training         = hourRow.Training,
                    Other            = hourRow.Other,
                    OtherExplanation = hourRow.OtherExplanation
                };
                ListOfHourRowModels.Add(newHourRowModel);
            }
            var selectedEmployee = context.Users.Single(p => p.Id == entity.EmployeeId);
            var castedEmployee   = (Employee)selectedEmployee;
            var employeeName     = castedEmployee.FirstName + " " + castedEmployee.LastName;

            string month = "";

            if (MonthConverter.ConvertMonthToInt(entity.Month) < 10)
            {
                month = 0 + MonthConverter.ConvertMonthToInt(entity.Month).ToString();
            }
            else
            {
                month = MonthConverter.ConvertMonthToInt(entity.Month).ToString();
            }
            string yearString      = entity.Year.ToString();
            string monthYearString = yearString + month;
            int    monthYear       = Convert.ToInt32(monthYearString);

            var newModel = new DeclarationFormModel
            {
                FormId           = entity.DeclarationFormId,
                HourRows         = ListOfHourRowModels,
                EmployeeId       = entity.EmployeeId,
                EmployeeName     = employeeName,
                Month            = entity.Month,
                Year             = entity.Year,
                monthyear        = monthYear,
                Approved         = entity.Approved,
                Submitted        = entity.Submitted,
                Comment          = entity.Comment,
                uniqueId         = entity.uniqueId,
                TotalWorkedHours = entity.TotalWorkedHours,
                TotalOvertime    = entity.TotalOvertime,
                TotalSickness    = entity.TotalSickness,
                TotalVacation    = entity.TotalVacation,
                TotalHoliday     = entity.TotalHoliday,
                TotalTraining    = entity.TotalTraining,
                TotalOther       = entity.TotalOther,
                DateCreated      = entity.DateCreated
            };

            return(newModel);
        }
Ejemplo n.º 14
0
        public async Task <List <DeclarationFormModel> > GetFormModelsFromEntities(List <DeclarationForm> entities)
        {
            var forms = new List <DeclarationFormModel>();

            foreach (var form in entities)
            {
                List <HourRowModel> ListOfHourRowModels = new List <HourRowModel>();

                foreach (HourRow hourRow in form.HourRows)
                {
                    HourRowModel newHourRowModel = new HourRowModel
                    {
                        HourRowId        = hourRow.HourRowId,
                        EmployeeId       = form.EmployeeId,
                        Date             = hourRow.Date,
                        Worked           = hourRow.Worked,
                        Overtime         = hourRow.Overtime,
                        Sickness         = hourRow.Sickness,
                        Vacation         = hourRow.Vacation,
                        Holiday          = hourRow.Holiday,
                        Training         = hourRow.Training,
                        Other            = hourRow.Other,
                        OtherExplanation = hourRow.OtherExplanation
                    };

                    ListOfHourRowModels.Add(newHourRowModel);
                }
                var selectedEmployee = await context.Users.SingleAsync(p => p.Id == form.EmployeeId);

                var castedEmployee = (Employee)selectedEmployee;
                var employeeName   = castedEmployee.FirstName + " " + castedEmployee.LastName;

                string month = "";
                if (MonthConverter.ConvertMonthToInt(form.Month) < 10)
                {
                    month = 0 + MonthConverter.ConvertMonthToInt(form.Month).ToString();
                }
                else
                {
                    month = MonthConverter.ConvertMonthToInt(form.Month).ToString();
                }
                string yearString      = form.Year.ToString();
                string monthYearString = yearString + month;
                int    monthYear       = Convert.ToInt32(monthYearString);

                var newModel = new DeclarationFormModel
                {
                    FormId           = form.DeclarationFormId,
                    HourRows         = ListOfHourRowModels,
                    EmployeeId       = form.EmployeeId,
                    EmployeeName     = employeeName,
                    Month            = form.Month,
                    Approved         = form.Approved,
                    Submitted        = form.Submitted,
                    Comment          = form.Comment,
                    Year             = form.Year,
                    monthyear        = monthYear,
                    uniqueId         = form.uniqueId,
                    TotalWorkedHours = form.TotalWorkedHours,
                    TotalOvertime    = form.TotalOvertime,
                    TotalSickness    = form.TotalSickness,
                    TotalVacation    = form.TotalVacation,
                    TotalHoliday     = form.TotalHoliday,
                    TotalTraining    = form.TotalTraining,
                    TotalOther       = form.TotalOther,
                    DateCreated      = form.DateCreated
                };

                forms.Add(newModel);
            }
            return(forms);
        }
Ejemplo n.º 15
0
        public async Task CreateForm(string employeeId)
        {
            var entities        = context.DeclarationForms.Where(p => p.EmployeeId == employeeId).ToList();
            var formModels      = EntitiesToDeclarationFormModels(entities);
            var ascendingModels = formModels.OrderBy(p => p.monthyear).ToList();

            if (formModels.Count() > 0)
            {
                var LastMonth = GetFormFromGap(ascendingModels);
                var monthInt  = 0;
                var entity    = new DeclarationFormModel();

                if (LastMonth != null)
                {
                    entity   = LastMonth;
                    monthInt = MonthConverter.ConvertMonthToInt(LastMonth.Month) + 1;
                }
                else
                {
                    entity   = ascendingModels[ascendingModels.Count() - 1];
                    monthInt = MonthConverter.ConvertMonthToInt(entity.Month) + 1;
                }

                if (monthInt == 13)
                {
                    monthInt = 1;
                }
                var monthString = MonthConverter.ConvertIntToMaand(monthInt);
                var year        = entity.Year;
                if (monthString == "Januari")
                {
                    year += 1;
                }

                if (monthInt == 1)
                {
                    monthInt = 13;
                }
                if (monthInt == 2 && DateTime.Now.Month != 1)
                {
                    monthInt = 14;
                }
                if (monthInt <= DateTime.Now.Month + 1)
                {
                    var form = new DeclarationForm
                    {
                        EmployeeId       = employeeId,
                        Month            = monthString,
                        Year             = year,
                        uniqueId         = GenerateUniqueId(),
                        Approved         = "Pending",
                        Submitted        = false,
                        TotalWorkedHours = 0,
                        TotalOvertime    = 0,
                        TotalSickness    = 0,
                        TotalVacation    = 0,
                        TotalHoliday     = 0,
                        TotalTraining    = 0,
                        TotalOther       = 0,
                        DateCreated      = DateTime.Now
                    };
                    await context.DeclarationForms.AddAsync(form);
                }
                else
                {
                    return;
                }
            }
            else
            {
                var form = new DeclarationForm
                {
                    EmployeeId       = employeeId,
                    Month            = MonthConverter.ConvertIntToMaand(DateTime.Now.Month),
                    Year             = DateTime.Now.Year,
                    uniqueId         = GenerateUniqueId(),
                    Approved         = "Pending",
                    Submitted        = false,
                    TotalWorkedHours = 0,
                    TotalOvertime    = 0,
                    TotalSickness    = 0,
                    TotalVacation    = 0,
                    TotalHoliday     = 0,
                    TotalTraining    = 0,
                    TotalOther       = 0,
                    DateCreated      = DateTime.Now
                };
                await context.DeclarationForms.AddAsync(form);
            }
            await context.SaveChangesAsync();
        }