Beispiel #1
0
        public async Task <IActionResult> UpdateLocation(string moniker, [FromBody] EventLocationViewModel vm)
        {
            try
            {
                var info = _repo.GetEventInfo(moniker);
                if (info == null)
                {
                    return(BadRequest("Cannot update a location on a missing event"));
                }
                else
                {
                    _mapper.Map(vm, info.Location);
                }

                _repo.AddOrUpdate(info.Location);
                await _repo.SaveChangesAsync();

                return(Ok(_mapper.Map <EventLocationViewModel>(info.Location)));
            }
            catch (Exception ex)
            {
                _logger.LogError("Failed to update location. {0}", ex);
            }

            return(BadRequest("Failed to save new location."));
        }
        public EventLocationViewModel convertDatesFromUtcToLocalTime(EventLocationViewModel sglEventVm)
        {
            sglEventVm.EventStartDate = sglEventVm.EventStartDate.ToLocalTime();
            sglEventVm.EventEndDate   = sglEventVm.EventEndDate.ToLocalTime();
            sglEventVm.DateCreated    = sglEventVm.DateCreated.ToLocalTime();

            return(sglEventVm);
        }
        // GET: Event
        public ActionResult Index()
        {
            List <Event>   events   = eventrepo.GetAllEvents();
            List <Locatie> locaties = new List <Locatie>();

            foreach (Event item in events)
            {
                locaties.Add(locrepo.GetByEvent(item));
            }
            var viewmodel = new EventLocationViewModel()
            {
                events   = events,
                locaties = locaties
            };

            return(View(viewmodel));
        }
        public EventLocationViewModel DisplayUserName(EventLocationViewModel sglEventVm)
        {
            var userId        = sglEventVm.ApplicationUserId;
            var userFirstName = _repo.Query <ApplicationUser>().Where(au => au.Id == userId).Select(au => au.FirstName).FirstOrDefault();
            var userLastName  = _repo.Query <ApplicationUser>().Where(au => au.Id == userId).Select(au => au.LastName).FirstOrDefault();

            sglEventVm.ApplicationUserId = userFirstName + " " + userLastName;

            foreach (var comment in sglEventVm.Comments)
            {
                var commentWriterId        = comment.ApplicationUserId;
                var commentWriterFirstName = _repo.Query <ApplicationUser>().Where(au => au.Id == commentWriterId).Select(au => au.FirstName).FirstOrDefault();
                comment.ApplicationUserId = commentWriterFirstName;
            }

            return(sglEventVm);
        }
Beispiel #5
0
        public IActionResult Post([FromBody] EventLocationViewModel addedEvent)
        {
            if (addedEvent.EventStartDate == new System.DateTime(0001, 01, 01))
            {
                ModelState.AddModelError("EventStartDate", "Event Start Date is required");
            }
            if (addedEvent.EventEndDate == new System.DateTime(0001, 01, 01))
            {
                ModelState.AddModelError("EventEndDate", "Event End Date is required");
            }
            if (addedEvent.EventEndDate < addedEvent.EventStartDate)
            {
                ModelState.AddModelError("EventEndDate", "Event End Date has to be later than the start date");
            }
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var  userId   = _userManager.GetUserId(User);
            bool hasClaim = User.HasClaim("IsAdmin", "true");

            _service.SaveEvent(userId, hasClaim, addedEvent);
            return(Ok());
        }
        //ToDo: If a member Deletes its event, an email is sent to the Admin
        //- Both Members can Add, Edit and Delete their own events (limited to one location per event),
        //Admin has permission to CRUD all events and Add Additional Location to an Event (if requried).
        #region My Event and Admin Event - Create, Delete, and Update
        /// <summary>
        /// Both Member(My Event) and Admin - Saves an event with one location
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="hasClaim"></param>
        /// <param name="addedEvent"></param>
        /// <returns></returns>
        public void SaveEvent(string userId, bool hasClaim, EventLocationViewModel addedEvent)
        {
            Event eventData;

            if (addedEvent.EventId == 0)
            {
                eventData = new Event
                {
                    EventTitle = addedEvent.EventTitle,
                    EventType  = addedEvent.EventType,
                    Details    = addedEvent.Details,
                    PreferredNumberOfExpectedVolunteer = addedEvent.PreferredNumberOfExpectedVolunteer,
                    DownVote            = 0,
                    UpVote              = 0,
                    EventStartDate      = addedEvent.EventStartDate.ToUniversalTime(),
                    EventEndDate        = addedEvent.EventEndDate.ToUniversalTime(),
                    IsComplete          = addedEvent.IsComplete,
                    IsPrivate           = addedEvent.IsPrivate,
                    IsVolunteerRequired = addedEvent.IsVolunteerRequired,
                    Views                       = 0,
                    ApplicationUserId           = userId,
                    NumberOfVolunteerRegistered = 0,
                    ApprovedByAdmin             = false,
                    DateCreated                 = DateTime.UtcNow,
                    IsActive                    = true
                };
                _repo.Add(eventData);
                var newEvent = _repo.Query <Event>().Where(e => e.Id == eventData.Id).Include(e => e.Locations).FirstOrDefault();
                //adds the location
                newEvent.Locations.Add(new Location
                {
                    NameOfLocation = addedEvent.NameOfLocation,
                    Address        = addedEvent.Address,
                    City           = addedEvent.City,
                    State          = addedEvent.State,
                    Zip            = addedEvent.Zip,
                    IsActive       = true,
                    DateCreated    = DateTime.UtcNow,
                    CreatedBy      = userId
                });

                _repo.SaveChanges();
            }
            else
            {
                var eventToEdit = _repo.Query <Event>().Where(e => e.Id == addedEvent.EventId).Include(e => e.Locations).FirstOrDefault();

                eventToEdit.EventTitle          = addedEvent.EventTitle;
                eventToEdit.EventStartDate      = addedEvent.EventStartDate.ToUniversalTime();
                eventToEdit.EventEndDate        = addedEvent.EventEndDate.ToUniversalTime();
                eventToEdit.IsComplete          = addedEvent.IsComplete;
                eventToEdit.IsPrivate           = addedEvent.IsPrivate;
                eventToEdit.IsVolunteerRequired = addedEvent.IsVolunteerRequired;
                eventToEdit.Views                       = eventToEdit.Views;
                eventToEdit.ApplicationUserId           = eventToEdit.ApplicationUserId;
                eventToEdit.DateCreated                 = eventToEdit.DateCreated;
                eventToEdit.IsActive                    = true;
                eventToEdit.NumberOfVolunteerRegistered = eventToEdit.NumberOfVolunteerRegistered;
                eventToEdit.ApprovedByAdmin             = eventToEdit.ApprovedByAdmin;

                //eventToEdit.Locations.Add(new Location
                //{
                //    NameOfLocation = addedEvent.LocationNameOfLocation,
                //    Address = addedEvent.LocationAddress,
                //    City = addedEvent.LocatinoCity,
                //    State = addedEvent.LocationState,
                //    Zip = addedEvent.LocationZip,
                //    IsActive = true,
                //    DateCreated = DateTime.UtcNow,
                //});

                _repo.SaveChanges();
            }
        }