public async Task <ContentResult> DeleteBooking(GetBookingInput input) { ReturnMessage returnmessage = new ReturnMessage(1, "Booking Cancelled"); try { var booking = await Task.Run(() => _unitOfWork.Bookings.GetAsync(filter: w => w.Id == input.Id)); if (booking.Count() == 0) { returnmessage.msgCode = -2; returnmessage.msg = "Booking Not Found"; } else { _unitOfWork.Bookings.Remove(booking.First()); } _unitOfWork.Complete(); _logger.LogInformation("Log:Delete Booking for ID: {Id}", input.Id); return(this.Content(returnmessage.returnMessage(null), "application/json")); } catch (Exception ex) { returnmessage.msg = ex.Message.ToString(); returnmessage.msgCode = -3; return(this.Content(returnmessage.returnMessage(null))); } }
public async Task <ContentResult> GetBooking(GetBookingInput input) { try { IEnumerable <Booking> bookings; ReturnMessage rm = new ReturnMessage(1, "Success"); var current_user = HttpContext.Session.GetObjectFromJson <RegisterUserDto>("current_user"); if (current_user.BranchId != 3 || current_user.UserRole == "Staff") { var users = await Task.Run(() => _unitOfWork.BranchStaff.GetAsync(filter: w => w.BranchId == current_user.BranchId, includeProperties: "Staff")); List <string> usersinbranch = new List <string>(); foreach (var item in users) { usersinbranch.Add(item.Staff.UserName); } bookings = await Task.Run(() => _unitOfWork.Bookings.GetAsync(filter: w => ((input.Id != 0 ? (w.Id == input.Id) : true) && ((w.ToBranchId == current_user.BranchId) || (w.FromBranchId == current_user.BranchId) || (usersinbranch.Contains(w.CreatedBy)))), includeProperties: "FromBranch,ToBranch,Car,Customer")); } else { bookings = await Task.Run(() => _unitOfWork.Bookings.GetAsync(filter: w => input.Id != 0 ? (w.Id == input.Id) : true, includeProperties: "FromBranch,ToBranch,Car,Customer")); } var bookingdToReturn = _mapper.Map <IEnumerable <BookingDto> >(bookings); foreach (var item in bookingdToReturn) { item.bookingextras = GetBookingExtras(new GetBookingExtraInput() { BookingId = item.Id }); var invoice = _unitOfWork.Invoices.Find(x => x.BookingId == item.Id).First(); item.Invoice = _mapper.Map <InvoiceDto>(invoice); } return(this.Content(rm.returnMessage(new PagedResultDto <BookingDto> (bookingdToReturn.AsQueryable(), input.pagenumber, input.pagesize)), "application/json")); } catch (Exception ex) { return(this.Content(JsonConvert.SerializeObject(new { msgCode = -3, msg = ex.Message }), "application/json")); } }