public void UpdateDiscrepancy_Test()
        {
            // Given
            var user2 = new User {
                Username = "******", Email = "*****@*****.**", Id = Guid.NewGuid()
            };
            var discrepancy = new Discrepancy()
            {
                Created = DateTime.Now, DelayLength = 15, Id = Guid.NewGuid(), Reason = "Test Reason",
                Type    = Discrepancy.DiscrepancyType.Absence, User = user2, UserId = user2.Id
            };

            this.discrepancies.Add(discrepancy);

            var dto = new UpsertDiscrepancyDTO()
            {
                DelayLength = 15,
                Reason      = "Test Reason Updated",
                Type        = Discrepancy.DiscrepancyType.Absence
            };

            // When
            this.service.UpdateDiscrepancy(discrepancy.Id, dto);

            // Then
            Assert.Equal("Test Reason Updated", this.discrepancies.First().Reason);
        }
        public void UpdateDiscrepancy(Guid discrepancyId, UpsertDiscrepancyDTO dto)
        {
            var discrepancy = this.discrepancyRepository.GetById(discrepancyId);

            discrepancy.Reason      = dto.Reason;
            discrepancy.Type        = dto.Type;
            discrepancy.DelayLength = dto.DelayLength;

            this.discrepancyRepository.Update(discrepancy);
        }
        public IActionResult UpdateDiscrepancy(Guid discrepancyId, [FromBody] UpsertDiscrepancyDTO dto)
        {
            if (!this.discrepancyService.IsUserDiscrepancyIssuer(this.GetCurrentUserId(), discrepancyId))
            {
                return(Unauthorized());
            }

            this.discrepancyService.UpdateDiscrepancy(discrepancyId, dto);
            return(Ok());
        }
        private void SendNotification(UpsertDiscrepancyDTO dto, Guid userId, Event evt)
        {
            var team    = this.teamRepository.GetById(evt.TeamId);
            var manager = team.Manager;
            var players = team.Players.Select(membership => membership.User).ToList();

            players.Add(team.Manager);
            var currentUser = players.First(user => user.Id == userId);
            var body        =
                $"{currentUser.Username} has issued a {dto.Type} {(dto.Type == Discrepancy.DiscrepancyType.Delay ? $"( {dto.DelayLength} )" : "")} " +
                $"for the event {evt.Name} ({evt.Start} - {evt.End})";

            //this.mailService.SendMail(manager.Username, manager.Email, "Discrepancy Notification", body);
        }
        public void AddDiscrepancy(Guid eventId, UpsertDiscrepancyDTO dto, Guid userId)
        {
            var evt         = this._eventRepository.GetById(eventId);
            var discrepancy = new Discrepancy()
            {
                Created     = DateTime.Now,
                Reason      = dto.Reason,
                Type        = dto.Type,
                DelayLength = dto.DelayLength,
                EventId     = eventId,
                UserId      = userId
            };

            evt.AddDiscrepancy(discrepancy);

            this._eventRepository.Update(evt);
        }
Example #6
0
        void AddDiscrepancy_Test()
        {
            // Given
            var user = new User {
                Username = "******", Email = "*****@*****.**", Id = Guid.Empty
            };
            var evt = new Event()
            {
                Id             = Guid.NewGuid(),
                Name           = "Test Event",
                Description    = "Test Event Description",
                Start          = DateTime.Now,
                End            = DateTime.Now,
                Discrepancies  = new List <Discrepancy>(),
                Participations = new List <Participation>()
                {
                    new Participation()
                    {
                        Created = DateTime.Now, User = user, UserId = user.Id
                    }
                },
                Created = DateTime.Now,
                Type    = Event.EventType.Coaching
            };

            events.Add(evt);

            var dto = new UpsertDiscrepancyDTO()
            {
                Reason      = "Test reason",
                Type        = Discrepancy.DiscrepancyType.Delay,
                DelayLength = 15,
            };

            // When
            this._eventService.AddDiscrepancy(evt.Id, dto, user.Id);

            // Then
            Assert.Equal(1, evt.Discrepancies.Count);
            Assert.Equal("Test reason", evt.Discrepancies.First().Reason);
        }
 public IActionResult AddDiscrepancy(Guid eventId, [FromBody] UpsertDiscrepancyDTO dto)
 {
     this.eventService.AddDiscrepancy(eventId, dto, this.GetCurrentUserId());
     return(Ok());
 }