コード例 #1
0
ファイル: EventRepository.cs プロジェクト: TreatApp/treat-api
        public void CreateEvent(Event @event)
        {
            using (var db = new Database(_settings))
            using (var transaction = db.GetTransaction())
            {
                db.Insert(@event.Location);

                @event.LocationId = @event.Location.Id;
                @event.SlotsAvailable = @event.Slots;
                db.Insert(@event);

                foreach (var eventImage in @event.Images)
                {
                    eventImage.EventId = @event.Id;
                    db.Insert(eventImage);
                }

                foreach (var category in @event.Categories)
                {
                    db.Insert(new EventCategory
                    {
                        EventId = @event.Id,
                        CategoryId = category.Id
                    });
                }

                transaction.Complete();
            }
        }
コード例 #2
0
ファイル: EventRepository.cs プロジェクト: TreatApp/treat-api
 public void CreateEventRating(EventRating eventRating)
 {
     using (var db = new Database(_settings))
     using (var transaction = db.GetTransaction())
     {
         db.Insert(eventRating);
         var rating = Convert.ToDecimal(db.Query<EventRating>("where EventId = @0", eventRating.EventId).Average(r => r.Rating));
         db.Update<Event>("set Rating = @1 where Id = @0", eventRating.EventId, rating);
         transaction.Complete();
     }
 }
コード例 #3
0
ファイル: UserRepository.cs プロジェクト: TreatApp/treat-api
 public void CreateUserRating(UserRating userRating)
 {
     using (var db = new Database(_settings))
     using (var transaction = db.GetTransaction())
     {
         db.Insert(userRating);
         var rating = Convert.ToDecimal(db.Query<UserRating>("where UserId = @0", userRating.UserId).Average(r => r.Rating));
         db.Update<User>("set Rating = @1 where Id = @0", userRating.UserId, rating);
         transaction.Complete();
     }
 }
コード例 #4
0
ファイル: EventRepository.cs プロジェクト: TreatApp/treat-api
        public void UpdateEventRequest(EventRequest eventRequest)
        {
            using (var db = new Database(_settings))
            using (var transaction = db.GetTransaction())
            {
                db.Update<EventRequest>("set Status = @2 where EventId = @0 and UserId = @1", eventRequest.EventId, eventRequest.UserId, eventRequest.Status);

                if (eventRequest.Status == EventRequestStatus.Approved)
                    db.Update<Event>("set SlotsAvailable = SlotsAvailable - 1 where Id = @0", eventRequest.EventId);

                else if (eventRequest.Status == EventRequestStatus.Cancelled)
                    db.Update<Event>("set SlotsAvailable = SlotsAvailable + 1 where Id = @0", eventRequest.EventId);

                transaction.Complete();
            }
        }