Esempio n. 1
0
        public async Task AddNotice(NewNotice notice)
        {
            var tags = notice.Tags;

            notice.Tags = null;

            var dbNotice = _mapper.Map <Notice>(notice);

            dbNotice.CreationDateTime = DateTime.Now;
            dbNotice.CreatorId        = 1;
            await _noticeRepository.AddAsync(dbNotice);

            foreach (var tag in tags)
            {
                var dbTag = await _tagRepository.FirstOrDefaultAsync(t => t.Name == tag.Name);

                var binding = new NoticeTag()
                {
                    Notice = dbNotice,
                    Tag    = dbTag
                };

                await _noticeTagRepository.AddAsync(binding);
            }

            await _unitOfWork.CompleteAsync();
        }
        public async Task <IActionResult> AddNotice(NewNotice notice)
        {
            var tagsToAdd = notice.Tags.Where(t => t.Id == 0);

            foreach (var t in tagsToAdd)
            {
                await _tagService.AddTag(t);
            }

            await _noticeService.AddNotice(notice);

            return(Ok(notice));
        }
Esempio n. 3
0
 /// <summary>
 /// Function to convert a Client NewNotice to DAL Notice
 /// </summary>
 /// <param name="newNotice">Client NewNotice</param>
 /// <returns>DAL Notice</returns>
 public static DAL.Entities.Notice ToDal(this NewNotice newNotice)
 {
     if (newNotice == null)
     {
         return(null);
     }
     return(new DAL.Entities.Notice
     {
         Content = newNotice.Content,
         IdMovie = newNotice.IdMovie,
         IdUsers = newNotice.IdUsers,
     });
 }
Esempio n. 4
0
 /// <summary>
 /// Function to create a new Notice
 /// </summary>
 /// <param name="entity">NewNotice</param>
 /// <returns>int id of notice created</returns>
 public int Create(NewNotice entity)
 {
     return(Repository.Create(entity.ToDal()));
 }