public async Task <ActionResult> f_SetSeat(Cl_Seat a_Seat) { if (a_Seat != null && a_Seat.p_Row > 0 && a_Seat.p_Number > 0) { Cl_Session session = m_AppDbContext.p_Sessions.FirstOrDefault(s => s.p_ID == a_Seat.p_SessionID); if (session != null) { Cl_Seat seat = m_AppDbContext.p_Seats.FirstOrDefault(s => s.p_SessionID == session.p_ID && s.p_Row == a_Seat.p_Row && s.p_Number == a_Seat.p_Number); if (seat == null) { seat = a_Seat; m_AppDbContext.p_Seats.Add(seat); } else { seat.p_UserFIO = a_Seat.p_UserFIO; seat.p_Mobile = a_Seat.p_Mobile; seat.p_Price = a_Seat.p_Price; seat.p_TypeEmployment = a_Seat.p_TypeEmployment; seat.p_Comment = a_Seat.p_Comment; } await m_AppDbContext.SaveChangesAsync(); return(Json(seat)); } else { throw new Exception("Сеанс не найден"); } } else { throw new Exception("Место неопределено"); } }
public async Task <ActionResult> f_RemoveSeats(Guid[] a_SeatsID) { List <Cl_Seat> seats = new List <Cl_Seat>(); foreach (Guid seatID in a_SeatsID) { Cl_Seat seat = m_AppDbContext.p_Seats.Include(s => s.p_PromoCode).FirstOrDefault(s => s.p_ID == seatID); if (seat != null) { Cl_LogsHalls log = new Cl_LogsHalls(); log.p_UserID = m_AppDbContext.p_Users.First(u => u.UserName == User.Identity.Name).p_ID; log.p_SeatID = seat.p_ID; log.p_Date = DateTime.Now; log.p_TypeEmployment = Cl_Seat.E_TypeEmployment.Free; log.p_PromoCodeID = seat.p_PromoCodeID; log.p_Price = seat.p_TotalPrice; seat.p_UserFIO = ""; seat.p_Mobile = ""; seat.p_PromoCodeID = null; seat.p_TypeEmployment = Cl_Seat.E_TypeEmployment.Free; seat.p_Comment = ""; seats.Add(seat); m_AppDbContext.p_LogsHalls.Add(log); } } await m_AppDbContext.SaveChangesAsync(); return(Json(seats)); }
public async Task <ActionResult> f_ActionSeat(Guid[] a_SeatsID, string a_UserFIO, string a_Mobile, Guid?a_PromoCodeID, string a_Comment, Cl_Seat.E_TypeEmployment a_TypeEmployment) { List <Cl_Seat> seats = new List <Cl_Seat>(); foreach (Guid seatID in a_SeatsID) { Cl_Seat seat = m_AppDbContext.p_Seats.Include(s => s.p_PromoCode).FirstOrDefault(s => s.p_ID == seatID); if (seat != null) { Cl_LogsHalls log = new Cl_LogsHalls(); log.p_UserID = m_AppDbContext.p_Users.First(u => u.UserName == User.Identity.Name).p_ID; log.p_SeatID = seat.p_ID; log.p_Date = DateTime.Now; if (a_TypeEmployment == Cl_Seat.E_TypeEmployment.Free) { seat.p_UserFIO = ""; seat.p_Mobile = ""; seat.p_TypeEmployment = Cl_Seat.E_TypeEmployment.Free; seat.p_Comment = ""; } else { seat.p_UserFIO = a_UserFIO; seat.p_Mobile = a_Mobile; seat.p_PromoCodeID = a_PromoCodeID; seat.p_TypeEmployment = a_TypeEmployment; seat.p_Comment = a_Comment; } log.p_TypeEmployment = seat.p_TypeEmployment; if (a_PromoCodeID != null) { Cl_PromoCode pcode = await m_AppDbContext.p_PromoCodes.FirstOrDefaultAsync(p => p.p_ID == a_PromoCodeID); if (pcode != null) { seat.p_PromoCode = pcode; } } log.p_PromoCodeID = seat.p_PromoCodeID; log.p_Price = seat.p_TotalPrice; seats.Add(seat); m_AppDbContext.p_LogsHalls.Add(log); } } await m_AppDbContext.SaveChangesAsync(); m_AppDbContext.p_Seats.Include(s => s.p_PromoCode).Load(); return(Json(seats)); }