Esempio n. 1
0
        public async Task <Unit> Handle(CompleteCheckItemCommand request, CancellationToken cancellationToken)
        {
            var user   = _userAccessor.GetUser();
            var entity = await _context.CheckItems.FindAsync(request.Id);

            entity.IsCompleted       = true;
            entity.ApplicationUserId = Guid.Parse(user.FindFirst(ClaimTypes.NameIdentifier).Value);

            var loggedTime = new LoggedTime
            {
                UserId     = Guid.Parse(user.FindFirst(ClaimTypes.NameIdentifier).Value),
                Time       = request.LoggedTime,
                ActivityId = entity.ActivityId,
                TrackerId  = request.TrackerTypeId,
                DateOfWork = request.DateOfWorkValue
            };

            loggedTime.CreateEnd(Guid.NewGuid(), LoggedTimeAction.Update.ToString(),
                                 Guid.Parse(user.FindFirst(ClaimTypes.NameIdentifier).Value));

            entity.LoggedTimeId = loggedTime.Id;

            await _context.LoggedTimes.AddAsync(loggedTime, cancellationToken);

            var activity = await _context.Activities
                           .Include(a => a.LoggedTimes)
                           .FirstOrDefaultAsync(a => a.Id == request.ActivityId, cancellationToken);

            if (activity != null)
            {
                var estimatedTime           = activity.EstimatedHours ?? 0;
                var totalActivityLoggedTime = activity.LoggedTimes.Sum(lt => lt.Time);
                var actualPercentage        = (totalActivityLoggedTime * 100) / estimatedTime;

                if (activity.StartDate == null)
                {
                    activity.StartDate = request.DateOfWorkValue;
                }

                if (activity.ActivityStatus == ActivityStatus.New)
                {
                    activity.ActivityStatus = ActivityStatus.InProgress;
                }

                activity.Progress = (int)actualPercentage;

                _context.Activities.Update(activity);
            }

            _context.CheckItems.Update(entity);
            await _context.SaveChangesAsync(cancellationToken);

            return(Unit.Value);
        }
Esempio n. 2
0
 public override int GetHashCode()
 {
     unchecked
     {
         var hashCode = (ProjectName != null ? ProjectName.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (AssigneeName != null ? AssigneeName.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (ActivityName != null ? ActivityName.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (int)ActivityStatus;
         hashCode = (hashCode * 397) ^ (ActivityType != null ? ActivityType.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ EstimatedTime.GetHashCode();
         hashCode = (hashCode * 397) ^ LoggedTime.GetHashCode();
         hashCode = (hashCode * 397) ^ ProjectId.GetHashCode();
         hashCode = (hashCode * 397) ^ ActivityId.GetHashCode();
         hashCode = (hashCode * 397) ^ AssigneeId.GetHashCode();
         return(hashCode);
     }
 }
Esempio n. 3
0
 public bool Equals(ProjectLoggsDto other)
 {
     if (ReferenceEquals(null, other))
     {
         return(false);
     }
     if (ReferenceEquals(this, other))
     {
         return(true);
     }
     return(ProjectName == other.ProjectName &&
            AssigneeName == other.AssigneeName &&
            ActivityName == other.ActivityName &&
            ActivityStatus == other.ActivityStatus &&
            ActivityType == other.ActivityType &&
            EstimatedTime.Equals(other.EstimatedTime) &&
            LoggedTime.Equals(other.LoggedTime) &&
            ProjectId.Equals(other.ProjectId) &&
            ActivityId.Equals(other.ActivityId) &&
            AssigneeId.Equals(other.AssigneeId));
 }
Esempio n. 4
0
 public static UserLoggedTimeLookupModel Create(LoggedTime loggedTime)
 {
     return(Projection.Compile().Invoke(loggedTime));
 }
Esempio n. 5
0
 public static LoggedTimeDetailModel Create(LoggedTime loggedTime)
 {
     return(Projection.Compile().Invoke(loggedTime));
 }
Esempio n. 6
0
 public static ProjectReportLookupModel Create(LoggedTime activity)
 {
     return(Projection.Compile().Invoke(activity));
 }