コード例 #1
0
        public async Task <IActionResult> CreateAnnouncementUser([FromBody] AnnouncementUserResource announcementUserResource)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var announcementUser = mapper.Map <AnnouncementUserResource, AnnouncementUser>(announcementUserResource);

            announcementUser.AppUser      = userRepository.GetUserByEmail(announcementUserResource.To);
            announcementUser.Announcement = await announcementRepository.GetAnnouncement(announcementUserResource.AnnouncementId);

            repository.AddAnnouncementUser(announcementUser);
            await unitOfWork.Complete();

            announcementUser = await repository.GetAnnouncementUser(announcementUser.AnnouncementUserId);

            var result = mapper.Map <AnnouncementUser, AnnouncementUserResource>(announcementUser);

            return(Ok(result));
        }
コード例 #2
0
        public async Task <IActionResult> UpdateAnnouncementUser(int id, [FromBody] AnnouncementUserResource announcementUserResource)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var announcementUser = await repository.GetAnnouncementUser(id);

            if (announcementUser == null)
            {
                return(NotFound());
            }

            mapper.Map <AnnouncementUserResource, AnnouncementUser>(announcementUserResource, announcementUser);

            await unitOfWork.Complete();

            var result = mapper.Map <AnnouncementUser, AnnouncementUserResource>(announcementUser);

            return(Ok(result));
        }