Пример #1
0
        public OutputBase SaveAttendance(SaveAttendanceInput input)
        {
            var date     = new TimeStamp(Clock.Now, true).Date;
            var employee = _employeeRepository.FirstOrDefault(emp => emp.Number == input.EmployeeNumber);

            if (employee == null)
            {
                return new OutputBase {
                           Message = "Invalid employee number", Success = false
                }
            }
            ;

            var      checkIn  = new TimeStamp(date, true).AddHours(input.HourIn).AddMinutes(input.MuniteIn).Date;
            DateTime?checkOut = null;

            if (input.HourOut != null && input.MuniteOut != null)
            {
                checkOut = new TimeStamp(date, true).AddHours(input.HourOut.Value).AddMinutes(input.MuniteOut.Value).Date;
            }

            if (_attendanceRepository.Query(
                    q => q.Any(at => at.Date == input.Date && at.Id != input.Id)))
            {
                return(new OutputBase
                {
                    Message = string.Format("An attendance entry have already been made for {0} for {1}",
                                            employee.Fullname, date.ToShortDateString())
                });
            }
            var attendance = new AttendanceDto
            {
                ClockIn    = checkIn,
                ClockOut   = checkOut,
                Date       = date,
                EmployeeId = employee.Id,
                Id         = input.Id ?? 0
            };

            _attendanceRepository.InsertOrUpdate(Mapper.Map <Attendance>(attendance));
            return(new OutputBase {
                Message = "Attendance saved", Success = true
            });
        }
Пример #2
0
        public async Task <PartialViewResult> CreateOrEditModal(int?id)
        {
            var output = new AttendanceDto {
                Date = Clock.Now, ClockIn = Clock.Now
            };

            if (id != null)
            {
                try
                {
                    output = _timeService.GetAttendanceDto(new GetAttendanceDtoInput {
                        AttendanceId = id.Value
                    });
                }
                catch (Exception exception)
                {
                    //ignored 444
                }
            }


            var viewModel = new SaveAttendanceInput
            {
                Date           = output.Date,
                HourIn         = output.ClockIn != null ? output.ClockIn.Value.Hour : 0,
                MuniteIn       = output.ClockIn != null ? output.ClockIn.Value.Minute : 0,
                HourOut        = output.ClockOut != null ? output.ClockOut.Value.Hour : 0,
                MuniteOut      = output.ClockOut != null ? output.ClockOut.Value.Minute : 0,
                EmployeeNumber =
                    output.EmployeeId != 0
                        ? _employeeService.GetEmployee(new GetEmployeeInput {
                    EmployeeId = output.EmployeeId
                }).Number
                        : "",
                Id = id
            };

            var muniteNumbers = new List <string> {
                ""
            };

            for (var i = 0; i <= 60; i++)
            {
                muniteNumbers.Add(StringMethods.RoundOff(i.ToString(), 2));
            }

            var hourNumbers = new List <string> {
                ""
            };

            for (var i = 0; i <= 23; i++)
            {
                hourNumbers.Add(StringMethods.RoundOff(i.ToString(), 2));
            }


            ViewBag.CheckInHour    = new SelectList(hourNumbers, viewModel.HourIn);
            ViewBag.CheckInMunite  = new SelectList(muniteNumbers, viewModel.MuniteIn);
            ViewBag.CheckOutHour   = new SelectList(hourNumbers, viewModel.HourOut);
            ViewBag.CheckOutMunite = new SelectList(muniteNumbers, viewModel.MuniteOut);

            return(PartialView(viewModel));
        }