/// <summary>
        ///     Asynchronous method that returns a place model based on Id.
        /// </summary>
        /// <param name="placeId">Id of a place</param>
        /// <returns>Basic place model without related entities.</returns>
        public async Task <Place> GetPlace(Guid placeId)
        {
            using (var context = EventPlannerContext.Get())
            {
                var result = context.Places
                             .FirstOrDefault(e => e.Id == placeId);

                return(await Task.FromResult(Mapper.Map <Place>(result)));
            }
        }
Exemple #2
0
        /// <summary>
        ///     Asynchronous method that returns basic event model based on Id.
        /// </summary>
        /// <param name="eventId">Id of an event</param>
        /// <returns>Basic event model without related entities.</returns>
        public virtual async Task <Event> GetEventInfo(Guid eventId)
        {
            using (var context = EventPlannerContext.Get())
            {
                var result = context.Events
                             .FirstOrDefault(e => e.Id == eventId);

                return(await Task.FromResult(Mapper.Map <Event>(result)));
            }
        }
Exemple #3
0
        /// <summary>
        ///     Asynchronous method that returns a timeslot model based on Id.
        /// </summary>
        /// <param name="timeSlotId">Id of a timeslot</param>
        /// <returns>Basic timeslot model without related entities.</returns>
        public async Task <TimeSlot> GetTimeSlot(Guid timeSlotId)
        {
            using (var context = EventPlannerContext.Get())
            {
                var result = context.TimeSlots
                             .FirstOrDefault(e => e.Id == timeSlotId);

                return(await Task.FromResult(Mapper.Map <TimeSlot>(result)));
            }
        }
        /// <summary>
        ///     Asynchronous method that returns place vote model with related user based on place vote entity Id.
        /// </summary>
        /// <param name="voteForPlaceId">Id of an place vote entity</param>
        /// <returns>Place vote model with related user.</returns>
        public async Task <VoteForPlace> GetVoteForPlace(Guid voteForPlaceId)
        {
            using (var context = EventPlannerContext.Get())
            {
                var result = context.VotesForPlaces
                             .Include("User")
                             .FirstOrDefault(e => e.Id == voteForPlaceId);

                return(await Task.FromResult(Mapper.Map <VoteForPlace>(result)));
            }
        }
Exemple #5
0
        /// <summary>
        ///     Returns an event with its places and timeslots based on Id
        /// </summary>
        /// <param name="eventId">Id of an event</param>
        /// <returns>Event model with related places and timeslots.</returns>
        public virtual async Task <Event> GetFullEvent(Guid eventId)
        {
            using (var context = EventPlannerContext.Get())
            {
                var result = context.Events
                             .Include("Places")
                             .Include("TimeSlots")
                             .FirstOrDefault(e => e.Id == eventId);

                return(await Task.FromResult(Mapper.Map <Event>(result)));
            }
        }
Exemple #6
0
        /// <summary>
        ///     Asynchronous method that returns all existing events.
        /// </summary>
        /// <returns>List of events</returns>
        public async Task <List <Event> > GetAll()
        {
            using (var context = EventPlannerContext.Get())
            {
                var result = context.Events
                             .ToList()
                             .Select(Mapper.Map <Event>)
                             .ToList();

                return(await Task.FromResult(result));
            }
        }
Exemple #7
0
        /// <summary>
        ///     Asynchronous method that adds or update existed timeslot based on place entity.
        /// </summary>
        /// <param name="timeSlot">Timeslot entity</param>
        /// <returns>Returns created timeslot entity</returns>
        public async Task <TimeSlot> AddOrUpdate(TimeSlot timeSlot)
        {
            using (var context = EventPlannerContext.Get())
            {
                var entity = Mapper.Map <TimeSlotEntity>(timeSlot);

                context.TimeSlots.AddOrUpdate(entity);
                await context.SaveChangesAsync();

                return(Mapper.Map <TimeSlot>(entity));
            }
        }
        /// <summary>
        ///     Asynchronous method that adds or update en existed place vote based on place vote entity.
        /// </summary>
        /// <param name="voteForPlace">Place vote entity with related</param>
        /// <returns>Returns created place vote entity</returns>
        public virtual async Task <VoteForPlace> AddOrUpdate(VoteForPlace voteForPlace)
        {
            using (var context = EventPlannerContext.Get())
            {
                var entity = Mapper.Map <VoteForPlaceEntity>(voteForPlace);

                context.VotesForPlaces.AddOrUpdate(entity);
                await context.SaveChangesAsync();

                return(Mapper.Map <VoteForPlace>(entity));
            }
        }
        /// <summary>
        ///     Asynchronous method that adds or update existed place based on place entity.
        /// </summary>
        /// <param name="place">Place entity</param>
        /// <returns>Returns created place entity</returns>
        public async Task <Place> AddOrUpdate(Place place)
        {
            using (var context = EventPlannerContext.Get())
            {
                var entity = Mapper.Map <PlaceEntity>(place);

                context.Places.AddOrUpdate(entity);
                await context.SaveChangesAsync();

                return(Mapper.Map <Place>(entity));
            }
        }
        /// <summary>
        ///     Asynchronous method that returns basic places models based on event Id.
        /// </summary>
        /// <param name="eventId">Id of an event</param>
        /// <returns>List of basic place models without related votes entities.</returns>
        public virtual async Task <List <Place> > GetPlaceInfoByEvent(Guid eventId)
        {
            using (var context = EventPlannerContext.Get())
            {
                var result = context.Places
                             .Where(e => e.Event.Id == eventId)
                             .Select(Mapper.Map <Place>)
                             .ToList();

                return(await Task.FromResult(result));
            }
        }
Exemple #11
0
        /// <summary>
        ///     Asynchronous method that returns events based on organizer Id
        /// </summary>
        /// <param name="organizerId">Id of an organizer of an event</param>
        /// <returns>List of events based on organizer Id</returns>
        public virtual async Task <List <Event> > GetByOrganizer(string organizerId)
        {
            using (var context = EventPlannerContext.Get())
            {
                var result = context.Events
                             .Where(e => e.Organizer.Id == organizerId)
                             .ToList()
                             .Select(Mapper.Map <Event>)
                             .ToList();

                return(await Task.FromResult(result));
            }
        }
        /// <summary>
        ///     Asynchronous method that returns place votes based on user Id
        /// </summary>
        /// <param name="userId">Id of an voter</param>
        /// <returns>List of place votes based on user Id</returns>
        public async Task <List <VoteForPlace> > GetByUser(string userId)
        {
            using (var context = EventPlannerContext.Get())
            {
                var result = context.VotesForPlaces
                             .Where(e => e.User.Id == userId)
                             .ToList()
                             .Select(Mapper.Map <VoteForPlace>)
                             .ToList();

                return(await Task.FromResult(result));
            }
        }
        /// <summary>
        ///     Asynchronous method that returns all existing place votes.
        /// </summary>
        /// <returns>List of place votes</returns>
        public virtual async Task <List <VoteForPlace> > GetAll()
        {
            using (var context = EventPlannerContext.Get())
            {
                var result = context.VotesForPlaces
                             .Include("User")
                             .ToList()
                             .Select(Mapper.Map <VoteForPlace>)
                             .ToList();

                return(await Task.FromResult(result));
            }
        }
Exemple #14
0
        /// <summary>
        ///     Asynchronous method that returns a timeslot models with related entities based on event Id.
        /// </summary>
        /// <param name="eventId">Id of an event</param>
        /// <returns>List of timeslot models with related votes entities.</returns>
        public virtual async Task <List <TimeSlot> > GetTimeSlotWithVotesByEvent(Guid eventId)
        {
            using (var context = EventPlannerContext.Get())
            {
                var result = context.TimeSlots
                             .Where(e => e.EventId == eventId)
                             .Include("VotesForDate")
                             .Include("VotesForDate.User")
                             .Select(Mapper.Map <TimeSlot>)
                             .ToList();

                return(await Task.FromResult(result));
            }
        }
Exemple #15
0
        /// <summary>
        ///     Asynchronous method that deletes an event based on Id.
        /// </summary>
        /// <param name="eventId">Id of an event</param>
        /// <returns>True if successfully deleted or false if event does not exist</returns>
        public async Task <bool> Delete(Guid eventId)
        {
            using (var context = EventPlannerContext.Get())
            {
                var existing = context.Events.FirstOrDefault(e => e.Id == eventId);

                if (existing == null)
                {
                    return(false);
                }

                context.Events.Remove(existing);
                await context.SaveChangesAsync();

                return(true);
            }
        }
Exemple #16
0
        /// <summary>
        ///     Asynchronous method that adds or update en existed event based on event entity.
        /// </summary>
        /// <param name="ev">Event entity with related timeslots and places</param>
        /// <returns>Returns created event entity</returns>
        public virtual async Task <Event> AddOrUpdate(Event ev)
        {
            using (var context = EventPlannerContext.Get())
            {
                var entity = Mapper.Map <EventEntity>(ev);

                foreach (var t in entity.TimeSlots)
                {
                    context.Entry(t).State = (t.Id == default(Guid) ? EntityState.Added : EntityState.Modified);
                }

                foreach (var p in entity.Places)
                {
                    context.Entry(p).State = (p.Id == default(Guid) ? EntityState.Added : EntityState.Modified);
                }

                context.Events.AddOrUpdate(entity);
                await context.SaveChangesAsync();

                return(Mapper.Map <Event>(entity));
            }
        }
 public HomeController(EventPlannerContext context)
 {
     dbContext = context;
 }
 public UsersController(EventPlannerContext connect)
 {
     _dbConnector = connect;
 }