public Attendance(Guid identity, Guid employeeId, DateTimeOffset checkInDate, LocationsCheckInEnum locationCheckIn, DateTimeOffset?checkOutDate, TimeSpan?duration)
        {
            Identity        = identity;
            EmployeeId      = employeeId;
            CheckInDate     = checkInDate;
            LocationCheckIn = locationCheckIn;
            CheckOutDate    = checkOutDate;
            Duration        = duration;

            this.AddDomainEvent(new AttendanceCreated(this));
        }
Ejemplo n.º 2
0
        public Attendance CheckIn(DateTimeOffset checkInDate, LocationsCheckInEnum locationStatus, DateTimeOffset?checkOutDate, TimeSpan?duration)
        {
            //validation for the same CheckInDate
            if (Attendances.Count > 0)
            {
                if (Attendances.Select(o => o.CheckInDate.Date).Contains(checkInDate.Date))
                {
                    return(null);
                }
            }

            //validation for checkin more than current date
            var comparison2 = DateTimeOffset.Compare(checkInDate.Date, DateTimeOffset.Now.Date);

            if (comparison2 >= 1)
            {
                return(null);
            }

            var attendance = new Attendance(Guid.NewGuid(), this.Identity, checkInDate, locationStatus, checkOutDate, duration);

            if (Attendances == null)
            {
                Attendances = new List <Attendance>().AsReadOnly();
            }

            var list = Attendances.ToList();

            list.Add(attendance);

            ReadModel.Attendances.Add(new AttendanceReadModel(attendance));

            Attendances = list.AsReadOnly();

            return(attendance);
        }