public Result EditCinema(int cinemaId, CinemaInfo cinemaInfo) { if (!CinemaExists(cinemaId)) { return(new Result { ResultOk = false, Details = "Edited cinema does not exist.", }); } if (!CinemaInfoValid(cinemaInfo)) { return(new ResultCreated { ResultOk = false, Details = "Invalid cinema data." }); } var cinema = dbContext.Cinemas.FirstOrDefault(c => c.CinemaId == cinemaId); cinema.Name = cinemaInfo.Name; cinema.City = cinemaInfo.City; dbContext.SaveChanges(); return(new Result { ResultOk = true, }); }
private void ClearSessionSeats(int sessionId) { var sessionSeats = dbContext.SessionSeats .Where(ss => ss.Order == null && ss.Booked && ss.SessionId == sessionId); foreach (var seat in sessionSeats) { if (seat.LastTimeUpdated.AddMinutes(10) < DateTime.Now) { seat.Booked = false; seat.LastTimeUpdated = DateTime.Now; } } dbContext.SaveChanges(); }
public ResultCreated CreateOrder(OrderInfo orderInfo) { if (ValidateSeatList(orderInfo.SessionSeats)) { return(new ResultCreated { ResultOk = false, Details = "Invalid seats information." }); } if (!SessionExists(orderInfo.SessionSeats.FirstOrDefault())) { return(new ResultCreated { ResultOk = false, Details = "Such session does not exist." }); } if (!UserExists(orderInfo.UserId)) { return(new ResultCreated { ResultOk = false, Details = "Such user does not exist." }); } Order order = new Order { UserId = orderInfo.UserId, SessionSeats = new List <SessionSeat>() }; foreach (var sessionSeatId in orderInfo.SessionSeats) { order.SessionSeats.Add( dbContext.SessionSeats .FirstOrDefault(ss => ss.SessionSeatId == sessionSeatId) ); } dbContext.Orders.Add(order); dbContext.SaveChanges(); return(new ResultCreated { ResultOk = true, Id = order.OrderId }); }
public ResultCreated CreateFilm(FilmInfo filmInfo) { if (FilmExists(filmInfo.Name)) { return(new ResultCreated { ResultOk = false, Details = "Such film already exists." }); } if (!FilmInfoValid(filmInfo)) { return(new ResultCreated { ResultOk = false, Details = "Invalid film data." }); } dbContext.Films.Add(new Film { Name = filmInfo.Name, StartDate = filmInfo.StartDate, EndDate = filmInfo.EndDate, Duration = filmInfo.Duration, Description = filmInfo.Description }); dbContext.SaveChanges(); return(new ResultCreated { ResultOk = true, Id = dbContext.Films.Last().FilmId }); }
public Result Register(UserRegistrationInfo user) { if (!InputRegistrationDataValid(user)) { return(new Result { ResultOk = false, Details = "Incorrect data." }); } if (UserExists(user.Email)) { return(new Result { ResultOk = false, Details = "User with such e-mail already registed." }); } if (UserNameUsed(user.UserName)) { return(new Result { ResultOk = false, Details = "User with such username already registed." }); } dbContext.Users.Add(new User { FirstName = user.FirstName, LastName = user.LastName, Password = Utils.GetHash(user.Password), Email = user.Email, Role = "user", UserName = user.UserName }); dbContext.SaveChanges(); return(new RegistrationResult { ResultOk = true, Token = GenerateToken(user.Email) }); }