Beispiel #1
0
        public async Task <ActionResult> Create([Bind(Include = "Id,date_of_session,filmname,time_of_session,hallname,hallId,filmId,price_of_tickets")] sessions sessions)
        {
            if (ModelState.IsValid)
            {
                var film = db.films.Where(c => c.Id == sessions.filmId).FirstOrDefault();

                if (DateTime.Parse(sessions.date_of_session) >= DateTime.Parse(film.release_date))
                {
                    string todaydate = DateTime.Today.ToString("yyyy.MM.dd");
                    int    dd        = DateTime.Parse(todaydate).CompareTo(DateTime.Parse(sessions.date_of_session));
                    if (dd <= 0)
                    {
                        db.session.Add(sessions);
                        await db.SaveChangesAsync();

                        hall current_hall = db.halls
                                            .Where(d => d.Id == sessions.hallId).FirstOrDefault();
                        film current_film = db.films
                                            .Where(d => d.Id == sessions.filmId).FirstOrDefault();
                        int number_rows  = current_hall.number_of_rows;
                        int number_seats = current_hall.number_of_seats_in_a_row;
                        for (int i = 1; i < number_rows + 1; i++)
                        {
                            for (int j = 1; j < number_seats + 1; j++)
                            {
                                places place = new places();
                                {
                                    place.sessionsId              = sessions.Id;
                                    place.number_of_row           = i;
                                    place.number_of_seat_in_a_row = j;
                                    place.status = "Свободно";

                                    //place.date_of_operation = DateTime.Now;
                                };

                                db.places_list.Add(place);
                                await db.SaveChangesAsync();
                            }
                        }
                        return(RedirectToAction("Index"));
                    }
                    else
                    {
                        ModelState.AddModelError("date_of_session", "Неверная дата начала сеанса. Введите коррекную дату(Нельзя задать прошедший день)");
                    }
                }
                else
                {
                    ModelState.AddModelError("date_of_session", "Неверная дата начала сеанса. Введите коррекную дату(позднее даты релиза фильма)");
                }
            }
            ViewBag.filmId = new SelectList(db.films, "Id", "film_name", sessions.filmId);
            ViewBag.hallId = new SelectList(db.halls, "Id", "hall_name", sessions.hallId);
            return(View(sessions));
        }
Beispiel #2
0
        public async Task <ActionResult> Create([Bind(Include = "hall_name,type,number_of_rows,number_of_seats_in_a_row")] hall hall)
        {
            if (ModelState.IsValid)
            {
                db.halls.Add(hall);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(hall));
        }
        public async Task <ActionResult> Create([Bind(Include = "Id,Country,budget,style,release_date,age_rating,duration,distributor,regisseur,film_name")] film film)
        {
            if (ModelState.IsValid)
            {
                db.films.Add(film);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(film));
        }
Beispiel #4
0
        public async Task <IActionResult> Delete(int id)
        {
            Home home = await dbContext.Homes.FirstOrDefaultAsync(x => x.Id == id);

            if (home is null)
            {
                return(NotFound());
            }
            dbContext.Homes.Remove(home);
            await dbContext.SaveChangesAsync();

            return(Ok());
        }
        public async Task <IActionResult> Post(MeterValueByHomeReqyest request)
        {
            if (request.value < 0)
            {
                return(BadRequest());
            }

            Home home = await dbContext.Homes.Where(x => x.Id == request.homeId).Include(i => i.Meter.Where(w => w.DateEnd == null)).FirstOrDefaultAsync();

            if (home is null)
            {
                return(NotFound());
            }

            home.Meter.First().MeterReading.Add(new MeterReading {
                Value = request.value
            });
            await dbContext.SaveChangesAsync();

            return(Ok());
        }
Beispiel #6
0
        public async Task <IActionResult> Post(Meter meter)
        {
            DateTime date = DateTime.Now;
            await dbContext.Meters.Where(x => x.DateEnd == null && x.HomeId == meter.HomeId).ForEachAsync(f => { f.DateEnd = date; dbContext.Meters.Update(f); });

            meter.MeterReading = new List <MeterReading> {
                new MeterReading {
                    MeterId = meter.Id, Value = 0
                }
            };
            dbContext.Meters.Add(meter);

            await dbContext.SaveChangesAsync();

            return(Ok());
        }
        public async Task <ActionResult> BuyTicket(int id)
        {
            if (User.Identity.IsAuthenticated == false)
            {
                return(RedirectToAction("Login", "Account"));
            }
            else
            {
                places places = await db.places_list.FindAsync(id);

                places.status = "Куплено";
                var user = db.Users.Where(c => c.Email == User.Identity.Name).FirstOrDefault();
                places.UserId = user.Id;
                DateTime data = new DateTime();
                data = DateTime.Now;
                places.date_of_operation        = data;
                db.Entry <places>(places).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index", "sessions"));
            }
        }
Beispiel #8
0
        public virtual async Task CommitAsync()
        {
            using (var _dbTransaction = _dbContext.Database.BeginTransaction())
            {
                try
                {
                    await _dbContext.SaveChangesAsync();

                    _dbTransaction.Commit();
                }
                catch (DbUpdateException dbEx)
                {
                    _dbTransaction.Rollback();
                    throw dbEx;
                }
                catch (Exception ex)
                {
                    _dbTransaction.Rollback();
                    throw ex;
                }
            }
        }
Beispiel #9
0
        public async Task <ActionResult> Edit([Bind(Include = "Id, Email,Password, user_surname, user_name,user_otc, Age")] User user)
        {
            if (User.Identity.IsAuthenticated == true)
            {
                if (ModelState.IsValid)
                {
                    using (MsSqlContext dd = new MsSqlContext())
                    {
                        var users = dd.Users.FirstOrDefault(c => c.Email == User.Identity.Name);
                        user.Password = users.Password;
                    }
                    user.Email           = User.Identity.Name;
                    db.Entry(user).State = EntityState.Modified;
                    await db.SaveChangesAsync();

                    return(RedirectToAction("Details"));
                }
            }
            else
            {
                return(RedirectToAction("Login"));
            }
            return(View(user));
        }
Beispiel #10
0
        public async Task <bool> SaveChangesAsync()
        {
            await _context.SaveChangesAsync();

            return(true);
        }