Пример #1
0
        /// <summary>
        /// Agrega un horario si todavia no se ha agregado ningun horario hoy. Si ya se agrego un horario el dia de hoy lo modifica.
        /// </summary>
        /// <param name="dto"></param>
        public void Add(HorariosDto dto)
        {
            var exist = GetToday(dto.EmployeeId);

            if (exist == null)
            {
                var toAdd = new Horarios
                {
                    EmployeeId = dto.EmployeeId,
                    StartlHour = dto.StartlHour,
                    FinishHour = dto.FinishHour
                };
                horarioRepository.Add(toAdd);
            }
            else
            {
                var toAdd = new Horarios
                {
                    ID         = exist.Id,
                    EmployeeId = exist.EmployeeId,
                    StartlHour = dto.StartlHour,
                    FinishHour = dto.FinishHour
                };
                horarioRepository.Update(toAdd);
            }
            horarioRepository.SaveChanges();
        }
Пример #2
0
        public ActionResult NewHourIn(int Id, int employeeId, DateTime checkIn, DateTime?checkOut)
        {
            var model = new HorariosDto
            {
                EmployeeId = employeeId,
                StartlHour = checkIn,
                FinishHour = checkOut
            };

            horarioServices.Add(model);

            return(View("Shifts"));
        }
Пример #3
0
        public ActionResult NewHourIn(int Id)
        {
            var h = horarioServices.GetToday(Id);

            if (h == null)
            {
                h = new HorariosDto
                {
                    Id         = 0,
                    EmployeeId = Id,
                    StartlHour = DateTime.Now
                };
            }
            return(View(h));
        }
Пример #4
0
        /// <summary>
        /// Obtiene los horarios de HOY de un empleado segun su ID. Devuelve null si no se ingreso ningun horario hoy.
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public HorariosDto GetToday(int id)
        {
            DateTime startDateTime = DateTime.Today;                         //Today at 00:00:00
            DateTime endDateTime   = DateTime.Today.AddDays(1).AddTicks(-1); //Today at 23:59:59

            var today = new HorariosDto();

            today = horarioRepository.Set()
                    .Where(c => c.EmployeeId == id && c.StartlHour >= startDateTime && c.StartlHour <= endDateTime)
                    .Select(c => new HorariosDto
            {
                Id         = c.ID,
                EmployeeId = c.EmployeeId,
                StartlHour = c.StartlHour,
                FinishHour = c.FinishHour
            })
                    .FirstOrDefault();

            return(today);
        }