Esempio n. 1
0
 public static ANEventRequestToJoinModel ToModel(ANEventRequestToJoin entity)
 {
     return(entity == null ? null : new ANEventRequestToJoinModel()
     {
         Id = entity.Id,
         ANEvent = new ANEventModel()
         {
             Id = entity.ANEventId.GetValueOrDefault()
         },
         User = new UserModel()
         {
             Id = entity.UserId.GetValueOrDefault()
         }
     });
 }
        public ANEventRequestToJoinModel JoinEvent([FromBody] int eventId)
        {
            var isExistInEventMember = this.ANDBUnitOfWork.ANEventMemberRepository.GetAll().Any(x => x.ANEventId.HasValue && x.ANEventId.Value == eventId && x.UserId.HasValue && x.UserId.Value == this.CurrentUser.Id);

            if (isExistInEventMember)
            {
                return(null);
            }

            var isEventHost = this.ANDBUnitOfWork.ANEventRepository.GetAll().Any(x => x.UserId.HasValue && x.UserId.Value == this.CurrentUser.Id && x.Id == eventId);

            if (isEventHost)
            {
                return(null);
            }

            var entityInRTJ = this.ANDBUnitOfWork.ANEventRequestToJoinRepository.GetAll().FirstOrDefault(x => x.ANEventId.HasValue && x.ANEventId.Value == eventId && x.UserId.HasValue && x.UserId.Value == this.CurrentUser.Id);

            if (entityInRTJ != null && entityInRTJ.Status == (int)Common.ANRequestToJoinStatus.Waiting)
            {
                return(null);
            }
            if (entityInRTJ == null)
            {
                entityInRTJ = new ANEventRequestToJoin()
                {
                    UserId      = this.CurrentUser.Id,
                    ANEventId   = eventId,
                    RequestDate = DateTimeHelper.DateTimeNow,
                };
            }
            entityInRTJ.Status = (int)Common.ANRequestToJoinStatus.Waiting;

            this.ANDBUnitOfWork.ANEventRequestToJoinRepository.Save(entityInRTJ);
            this.ANDBUnitOfWork.Commit();

            return(ANEventRequestToJoinMapper.ToModel(entityInRTJ));
        }