예제 #1
0
        public IActionResult CreateEvent([FromBody] EventCreateDto createEvent)
        {
            if (createEvent == null)
            {
                return(BadRequest(new TransActionResponse("No event entered")));
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(new TransActionResponse(ModelState)));
            }

            if (createEvent.StartDate > createEvent.EndDate)
            {
                return(BadRequest(new TransActionResponse("Start date cannot be greater than the end date")));
            }

            var newEvent = _mapper.Map <TraEvent>(createEvent);

            newEvent.IsActive = true;

            _unitOfWork.Event.Create(newEvent);

            if (!_unitOfWork.Save())
            {
                return(StatusCode(500, new TransActionResponse("A problem happened while handling your request.")));
            }

            var createEventResult = _mapper.Map <EventDto>(newEvent);

            return(CreatedAtRoute("GetEvent", new { id = createEventResult.EventId }, new TransActionResponse(createEventResult)));
        }
예제 #2
0
        public IActionResult CreateEvent([FromBody] EventCreateDto createEvent)
        {
            if (createEvent == null)
            {
                return(BadRequest());
            }
            if (createEvent.Description == null || createEvent.EndDate == null || createEvent.StartDate == null)
            {
                return(BadRequest());
            }
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            if (_transActionRepo.EventExists(createEvent.Name))
            {
                return(BadRequest());
            }

            var newEvent = Mapper.Map <TraEvent>(createEvent);


            _transActionRepo.CreateEvent(newEvent);

            if (!_transActionRepo.Save())
            {
                return(StatusCode(500, "A problem happened while handling your request."));
            }

            var createdPointOfInterestToReturn = Mapper.Map <EventDto>(newEvent);

            return(CreatedAtRoute("GetThatEvent", new { id = createdPointOfInterestToReturn.EventId }, createdPointOfInterestToReturn));
        }
예제 #3
0
        public async Task <IActionResult> CreateEvent([FromBody] EventCreateDto dto)
        {
            EventCreateDtoValidator validator = new EventCreateDtoValidator();
            ValidationResult        result    = await validator.ValidateAsync(dto);

            if (result.IsValid)
            {
                var userId = User.Claims
                             .Single(p => p.Type == "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier").Value;
                var administrator = await _dbContext.Administrators
                                    .AsNoTracking()
                                    .SingleOrDefaultAsync(x => x.ApplicationUserId == userId);

                #region 驗證

                if (!administrator.AdministratorConfirmed)
                {
                    return(Problem(title: "禁止修改", detail: "管理員尚未驗證", statusCode: 403));
                }

                #endregion

                var entity = _mapper.Map <Event>(dto);
                _dbContext.Events.Add(entity);
                await _dbContext.SaveChangesAsync();

                var routeValues = new { eventId = entity.EventId };
                var returnDto   = _mapper.Map <EventDto>(entity);
                return(CreatedAtAction(nameof(GetEvent), routeValues, returnDto));
            }
            return(BadRequest(result.Errors));
        }
예제 #4
0
        public async Task <IActionResult> Post([FromBody] EventCreateDto eventToCreate)
        {
            Event newEvent = await eventService.CreateNewEventAsync(eventToCreate);

            if (newEvent != null)
            {
                foreach (int contactId in eventToCreate.Contacts)
                {
                    await eventService.AddEventContactAsync(new EventContact()
                    {
                        ContactId = contactId, EventId = newEvent.Id
                    });
                }
                foreach (int orgaId in eventToCreate.Organizations)
                {
                    await eventService.AddEventOrganizationAsync(new EventOrganization()
                    {
                        OrganizationId = orgaId, EventId = newEvent.Id
                    });
                }
                var  uri          = $"https://{Request.Host}{Request.Path}/{_mapper.Map<EventDto>(newEvent).Id}";
                User userOfChange = await userService.FindByNameAsync(User.Identity.Name);

                await modService.CreateNewEventEntryAsync(userOfChange, newEvent.Id);

                return(Created(uri, eventToCreate));
            }
            return(BadRequest("Fehler beim erzeugen eines Events!"));
        }
예제 #5
0
        public ActionResult AddEvent(EventCreateDto newEvent)
        {
            var theEvent = mapper.Map <Event>(newEvent);

            repo.CreateEvent(theEvent);
            repo.SaveChanges();
            return(Ok(theEvent));
        }
예제 #6
0
        public async Task <ActionResult> CreateAsync([FromForm] EventCreateDto eventCreateDto)
        {
            _logger.LogMethodCallingWithObject(eventCreateDto);

            var hostRoot = _hostServices.GetHostPath();

            await _eventManager.AddEventAsync(eventCreateDto, hostRoot);

            return(Ok());
        }
예제 #7
0
        public async Task <IActionResult> CreateEvent([FromBody] EventCreateDto evtCrtDto)
        {
            var eventModel = _mapper.Map <Event>(evtCrtDto);
            var res        = await _repository.CreateEvent(eventModel);

            var evtRdDto = _mapper.Map <EventReadDto>(eventModel);

            // return CreatedAtRoute(nameof(GetEventById), new {Id = evtRdDto.Id}, evtRdDto);
            return(Ok(res));
        }
예제 #8
0
        public ActionResult <EventDto> CreateEvent([FromBody] EventCreateDto eventCreateDto)
        {
            var eventEntity = _mapper.Map <Event>(eventCreateDto);

            _eventRepository.AddEvent(eventEntity);
            _eventRepository.Save();

            var eventToReturn = _mapper.Map <EventDto>(eventEntity);

            return(CreatedAtRoute("GetEvent", new { id = eventToReturn.Id }, eventToReturn));
        }
예제 #9
0
        public async Task AddEventAsync(EventCreateDto eventDto, string hostRoot)
        {
            _logger.LogMethodCallingWithObject(eventDto);

            if (!eventDto.IsRecurrent && string.IsNullOrEmpty(eventDto.Start))
            {
                throw new ArgumentNullException(nameof(eventDto.Start));
            }

            var newEvent = _mapper.Map <EventCreateDto, Event>(eventDto);

            await _appContext.Events.AddAsync(newEvent);

            await _appContext.SaveChangesAsync(default);
예제 #10
0
 public static Event ToEntity(this EventCreateDto source)
 {
     return(new Event
     {
         Date = source.Date,
         Description = source.Description,
         EndDate = source.EndDate,
         PrimaryPicture = source.PrimaryPicture,
         StartDate = source.StartDate,
         Title = source.Title,
         Time = source.Time,
         MultiDay = source.MultiDay
     });
 }
예제 #11
0
        public async Task <Event> CreateNewEventAsync(EventCreateDto eventToCreate)
        {
            Event eventNew = new Event();

            eventNew.Date        = eventToCreate.Date;
            eventNew.Starttime   = eventToCreate.Starttime;
            eventNew.Name        = eventToCreate.Name;
            eventNew.Endtime     = eventToCreate.Endtime;
            eventNew.Description = eventToCreate.Description;
            eventNew.Location    = eventToCreate.Location;
            eventToCreate.Contacts.ForEach(x => eventNew.Participated.Add(new Participated()
            {
                ObjectId = x, HasParticipated = false, EventStatus = ParticipatedStatus.NOT_INVITED, ModelType = MODEL_TYPE.CONTACT
            }));
            eventToCreate.Organizations.ForEach(x => eventNew.Participated.Add(new Participated()
            {
                ObjectId = x, HasParticipated = false, EventStatus = ParticipatedStatus.NOT_INVITED, ModelType = MODEL_TYPE.ORGANIZATION
            }));
            return(await CreateAsync(eventNew));
        }
예제 #12
0
        public ActionResult <EventDto> AddEvent(ApiVersion version, [FromBody] EventCreateDto eventCreateDto)
        {
            if (eventCreateDto == null)
            {
                return(BadRequest());
            }

            EventEntity toAdd = _mapper.Map <EventEntity>(eventCreateDto);

            _eventRepository.Add(toAdd);

            if (!_eventRepository.Save())
            {
                throw new Exception("Creating an event failed on save.");
            }

            EventEntity newEventItem = _eventRepository.GetSingle(toAdd.EventId);

            return(CreatedAtRoute(nameof(GetSingleEvent), new { version = version.ToString(), id = newEventItem.EventId },
                                  _mapper.Map <EventDto>(newEventItem)));
        }
예제 #13
0
        public IActionResult CreateEvent([FromBody] EventCreateDto createEvent)
        {
            if (createEvent == null)
            {
                return(BadRequest());
            }

            // Use data annonation instead of doing this, see EventCreateDto
            //if (createEvent.Description == null || createEvent.EndDate == null || createEvent.StartDate == null)
            //{
            //    return BadRequest();
            //}

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (createEvent.StartDate > createEvent.EndDate)
            {
                return(BadRequest());
            }

            var newEvent = _mapper.Map <TraEvent>(createEvent);

            newEvent.IsActive = true;

            _unitOfWork.Event.Create(newEvent);

            if (!_unitOfWork.Save())
            {
                return(StatusCode(500, "A problem happened while handling your request."));
            }

            var createdPointOfInterestToReturn = _mapper.Map <EventDto>(newEvent);

            return(CreatedAtRoute("GetThatEvent", new { id = createdPointOfInterestToReturn.EventId }, createdPointOfInterestToReturn));
        }
예제 #14
0
        public EventDto CreateEvent(EventCreateDto dto)
        {
            _subscriptionService.CheckSubscription(dto.CompanyId);

            try
            {
                var repoUser = _contextManager.CreateRepositiry <IUserRepo>();
                var user     = repoUser.GetById(dto.UserId);

                if (user == null)
                {
                    throw new ValidationException("User not found");
                }
                var entity = _mapper.Map <Event>(dto);
                var repo   = _contextManager.CreateRepositiry <IEventRepo>();
                repo.Add(entity);
                _contextManager.Save();

                //add user to the event
                var repoEventUser = _contextManager.CreateRepositiry <IEventUserLinkRepo>();
                var eventUser     = new EventUserLink
                {
                    EventId       = entity.Id,
                    UserId        = user.Id,
                    UserEventRole = (int)Model.Enums.EventUserRoleEnum.Owner
                };
                repoEventUser.Add(eventUser);
                _contextManager.Save();

                return(_mapper.Map <EventDto>(entity));
            }
            catch
            {
                throw new ValidationException("Sorry, unexpected error.");
            }
        }
예제 #15
0
 public IActionResult CreateEvent([FromBody] EventCreateModel model)
 {
     try
     {
         var eventCreateDto = new EventCreateDto
         {
             Name             = model.Name,
             UserId           = model.UserId,
             Type             = model.Type,
             Description      = model.Description,
             CreateDate       = model.CreateDate,
             BeginHoldingDate = model.BeginHoldingDate,
             HoldingDate      = model.HoldingDate,
             EventTimeZone    = model.EventTimeZone,
             CompanyId        = model.CompanyId
         };
         var data = _service.CreateEvent(eventCreateDto);
         return(Ok(data));
     }
     catch (APIEventException ex)
     {
         return(BadRequest(ex.Message));
     }
 }
예제 #16
0
        public async Task <IActionResult> Create([FromBody] EventCreateDto eventCreate)
        {
            if (eventCreate == null)
            {
                return(BadRequest());
            }

            var username = User.GetUsername();
            var user     = await _unitOfWork.UserRepository.GetUserByUsername(username);

            var eventt = new Event
            {
                Title    = eventCreate.Title,
                Location = eventCreate.Location,
                City     = eventCreate.City,
                State    = eventCreate.State,
                Category = eventCreate.Category,
                Date     = eventCreate.Date
            };

            await _unitOfWork.EventRepository.CreateEventAsync(eventt);

            return(Ok(eventt));
        }
예제 #17
0
        public ServiceResult CreateEvent(EventCreateDto model)
        {
            var serviceResult = new ServiceResult(true);

            #region validation
            if (string.IsNullOrEmpty(model.Title))
            {
                serviceResult.AddError("عنوان برنامه نمی تواند فاقد مقدار باشد");
            }
            if (!string.IsNullOrEmpty(model.Title) && model.Title.Length > 128)
            {
                serviceResult.AddError("تعداد کاراکترهای عنوان برنامه نمی تواند بیش از 128 کاراکتر باشد".ToPersianNumbers());
            }
            if (string.IsNullOrEmpty(model.PrimaryPicture))
            {
                serviceResult.AddError("عکس اصلی برنامه نمی تواند فاقد مقدار باشد");
            }
            #endregion

            var entity = model.ToEntity();

            if (entity.MultiDay)
            {
                if (!entity.StartDate.HasValue)
                {
                    serviceResult.AddError("تاریخ شروع برنامه یا وارد نشده است و یا ساختارش اشتباه می باشد");
                }

                if (!entity.EndDate.HasValue)
                {
                    serviceResult.AddError("تاریخ پایان برنامه یا وارد نشده است و یا ساختارش اشتباه می باشد");
                }

                if (entity.StartDate.HasValue && entity.EndDate.HasValue)
                {
                    if (entity.EndDate.Value <= entity.StartDate.Value)
                    {
                        serviceResult.AddError("تاریخ پایان برنامه نمی تواند از تاریخ شروع برنامه کمتر باشد");
                    }
                }

                entity.Date = null;
                entity.Time = null;
            }
            else
            {
                if (!entity.Date.HasValue)
                {
                    serviceResult.AddError("تاریخ برنامه یا وارد نشده است و یا ساختارش اشتباه می باشد");
                }
                if (string.IsNullOrEmpty(entity.Time))
                {
                    serviceResult.AddError("ساعت برنامه نمی تواند فاقد مقدار باشد");
                }

                entity.StartDate = null;
                entity.EndDate   = null;
            }

            if (serviceResult.IsSuccess)
            {
                _context.Events.Add(entity);

                if (_context.SaveChanges() == 0)
                {
                    serviceResult.AddError("در انجام عملیات خطایی رخ داد");
                }
            }

            return(serviceResult);
        }