コード例 #1
0
        public async Task <ActionResult> Add(MeetingAddDTO dto)
        {
            try
            {
                string id = User.Claims.FirstOrDefault(x => x.Type == ClaimTypes.NameIdentifier)?.Value;

                await _meetingRepository.AddFromDTOAsync(dto, Convert.ToInt32(id));

                return(Ok());
            }
            catch (System.Exception ex)
            {
                return(Problem(ex.Message));
            }
        }
コード例 #2
0
        /// <summary>
        /// Add a meeting from DTO.
        /// </summary>
        /// <param name="dto">The DTO.</param>
        /// <param name="creatorID">Who create this meeting.</param>
        public async Task AddFromDTOAsync(MeetingAddDTO dto, int creatorID)
        {
            var creator = await _userRepository.Get(creatorID);

            var departments = await _departmentRepository.Find(x => dto.Departments.Any(n => n == x.Name)).ToListAsync();

            var room = await _roomRepository.Find(x => x.Name == dto.Location).FirstAsync();

            var attendees = await _userRepository.Find(u => dto.Attendees.Contains(u.ID)).ToListAsync();

            var entity = new Meeting();

            entity.Title       = dto.Title;
            entity.Description = dto.Description;
            entity.Attendees   = attendees;
            entity.Location    = room;
            entity.Departments = departments;
            entity.Creator     = creator;
            entity.FromDate    = dto.FromDate;
            entity.ToDate      = dto.ToDate;

            if (await ValidateMeetingAsync(entity))
            {
                await this.Add(entity);

                await _mailService.SendMail(
                    "New meeting!",
                    $"<p>You have been invited to the meeting '{entity.Title}'</p>" +
                    $"<p>Description: { (String.IsNullOrEmpty(entity.Description) ? "Empty" : entity.Description) }</p>" +
                    $"<p>The Host: { entity.Creator.Name }</p>" +
                    $"<p>The location is {entity.Location.Name}</p>" +
                    $"<p>The Departments of this meeting is {String.Join(",", departments.Select(x => x.Name))} </p>" +
                    $"<p>The meeting will start on {entity.FromDate}. End on {entity.ToDate} </p>",
                    MailType.MeetingCreated,
                    entity.Attendees.Select(x => x.Email)
                    );
            }
        }