public void UpdateEventStatus(long hostId, UpdateEventStatusRequest value) { using (var context = new AnnoDBContext()) { var record = context.Events.SingleOrDefault(x => x.host_id == hostId && x.ref_id == value.ReferenceId && x.record_status == RecordStatuses.Live); if (record != null) { record.status = value.NewStatus; context.SaveChanges(); } } }
public string CancelEvent(long hostId, CancelEventRequest value) { //Validate if event EventsServices eventsServices = new EventsServices(); EventInfo eventInfo = eventsServices.GetEventByRef(hostId, value.ReferenceId); if (eventInfo == null) { return(CancelEventStatuses.EventNotFound); } //Validate event status if (eventInfo.Status != EventStatuses.Active) { return(CancelEventStatuses.EventNotActive); } //Validate if event start date is over if (DateTime.UtcNow >= eventInfo.StartDate) { return(CancelEventStatuses.EventHasAlreadyStarted); } //Cancel and Refund all tickets BookingServices bookingService = new BookingServices(); var tickets = bookingService.GetTicketsByEvent(hostId, value.ReferenceId); if (tickets != null) { foreach (var ticket in tickets) { string status = null; CancelAndRefundTicket(hostId, ticket.TicketId.Value, out status); //Not required to check on status as cancel event will try to cancel and refund all tickets } } //Update event status to Cancelled UpdateEventStatusRequest req = new UpdateEventStatusRequest(); req.ReferenceId = value.ReferenceId; req.NewStatus = EventStatuses.Cancelled; UpdateEventStatus(hostId, req); return(CancelEventStatuses.Success); }
public ClaimEarningsResponse ClaimEarnings(long hostId, ClaimEarningsRequest value, out string status) { ClaimEarningsResponse result = null; //Get event var eventInfo = GetEventByRef(hostId, value.ReferenceId); if (eventInfo == null) { status = ClaimEarningsStatuses.EventNotFound; return(null); } //Check event status if (eventInfo.Status == EventStatuses.Cancelled) { status = ClaimEarningsStatuses.EventAlreadyCancelled; return(null); } if (eventInfo.Status == EventStatuses.Closed) { status = ClaimEarningsStatuses.EventAlreadyClaimed; return(null); } //Check if event has already started if (DateTime.UtcNow < eventInfo.StartDate.Value) { status = ClaimEarningsStatuses.EventNotStarted; return(null); } //Get host HostServices hostServices = new HostServices(); var host = hostServices.GetHostInfoById(hostId); if (host == null) { status = ClaimEarningsStatuses.HostNotFound; return(null); } //Transfer event wallet balance to host wallet WalletServices walletServices = new WalletServices(); walletServices.Transfer(eventInfo.WalletAddress, host.WalletAddress, eventInfo.WalletBalance.Value, null, "Claim"); //Update event status UpdateEventStatusRequest req = new UpdateEventStatusRequest(); req.ReferenceId = eventInfo.ReferenceId; req.NewStatus = EventStatuses.Closed; UpdateEventStatus(hostId, req); //Commit to blockchain ContractApi blockchainContract = new ContractApi(); blockchainContract.ClaimEarnings(eventInfo.EventUniqueId); status = ClaimEarningsStatuses.Success; result = new ClaimEarningsResponse(); result.EventTitle = eventInfo.Title; result.Earnings = eventInfo.WalletBalance.Value; return(result); }