Beispiel #1
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);
        }
Beispiel #2
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);
        }