public async Task <IHttpActionResult> SendRequest([FromBody] AddRequestVM model) { var userEmail = Request.GetOwinContext().Request.User.Identity.Name; using (var context = new ApplicationDbContext()) { var enquiry = await context.UserEnquireis.Where(i => i.Id == model.EnquiryId).Include("User").FirstOrDefaultAsync(); var currentUser = context.Users.Where(i => i.Email == userEmail).FirstOrDefault(); var currentUserEnquiry = await context.UserEnquireis.Where(i => i.UserId == currentUser.Id && i.ActiveTill > DateTime.Now).FirstOrDefaultAsync(); if (enquiry != null && currentUserEnquiry != null) { var booking = new BaggageRequest() { ApprovedCost = model.Amount, MoverEnquiryrId = model.Type == RequestType.Baggage ? currentUserEnquiry.Id : enquiry.Id, RequesterEnquiryId = model.Type == RequestType.Travel ? currentUserEnquiry.Id : enquiry.Id, BookingStatus = BookingStatus.Waiting, StartTime = new DateTime(), EndTime = new DateTime(), ApproximateWeight = "0" }; context.BaggageRequests.Add(booking); await context.SaveChangesAsync(); var notificaiton = new Notification() { NotificationType = NotificationType.Booking, Message = "You have new " + (model.Type == RequestType.Baggage ? " travel" : " baggage") + " Request, please find the details", NotificationId = booking.Id, UserId = enquiry.UserId }; context.Notifications.Add(notificaiton); await context.SaveChangesAsync(); } return(Ok()); } }
public static void PublishBaggageRequest(BaggageRequest request) => Publish(baggageRequestsQueueName, request);