Пример #1
0
        public async Task <IActionResult> Create([Bind("id,name,status")] Category category)
        {
            if (ModelState.IsValid)
            {
                _context.Add(category);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(category));
        }
Пример #2
0
        public async Task <IActionResult> Create([Bind("id,name,discount_percent,status")] Discount discount)
        {
            if (ModelState.IsValid)
            {
                _context.Add(discount);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(discount));
        }
Пример #3
0
        public async Task <IActionResult> Create([Bind("id,reason,content,review_id,create_date,status")] Report report)
        {
            if (ModelState.IsValid)
            {
                _context.Add(report);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["review_id"] = new SelectList(_context.reviews, "id", "id", report.review_id);
            return(View(report));
        }
Пример #4
0
        public async Task <IActionResult> Create([Bind("id,user_id,total_price,status,create_date")] Order order)
        {
            if (ModelState.IsValid)
            {
                _context.Add(order);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["user_id"] = new SelectList(_context.users, "id", "id", order.user_id);
            return(View(order));
        }
Пример #5
0
        public async Task <IActionResult> Create([Bind("id,room_id,position")] Seat seat)
        {
            if (ModelState.IsValid)
            {
                _context.Add(seat);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["room_id"] = new SelectList(_context.rooms, "id", "name", seat.room_id);
            return(View(seat));
        }
Пример #6
0
        public async Task <IActionResult> Create([Bind("id,user_id,content,status,create_date")] ContactForm contactForm)
        {
            if (ModelState.IsValid)
            {
                _context.Add(contactForm);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["user_id"] = new SelectList(_context.users, "id", "id", contactForm.user_id);
            return(View(contactForm));
        }
Пример #7
0
        public async Task <IActionResult> Create([Bind("id,user_id,movie_id,content,heart_rate,create_date")] Review review)
        {
            if (ModelState.IsValid)
            {
                _context.Add(review);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["movie_id"] = new SelectList(_context.movies, "id", "id", review.movie_id);
            ViewData["user_id"]  = new SelectList(_context.users, "id", "id", review.user_id);
            return(View(review));
        }
Пример #8
0
        public async Task <IActionResult> Create([Bind("id,name,address,status")] Branch branch)
        {
            if (ModelState.IsValid)
            {
                _context.Add(branch);
                await _context.SaveChangesAsync();

                SetAlert("Created success !");
                return(RedirectToAction(nameof(Index)));
            }
            SetAlert("Created fail !");
            return(View(branch));
        }
Пример #9
0
        public async Task <IActionResult> Create([Bind("id,order_id,schedule_id,price")] Ticket ticket)
        {
            if (ModelState.IsValid)
            {
                _context.Add(ticket);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["order_id"]    = new SelectList(_context.orders, "id", "id", ticket.order_id);
            ViewData["schedule_id"] = new SelectList(_context.schedules, "id", "id", ticket.schedule_id);
            return(View(ticket));
        }
Пример #10
0
        public async Task <IActionResult> Create([Bind("id,room_id,movie_id,start_time")] Schedule schedule)
        {
            if (ModelState.IsValid)
            {
                _context.Add(schedule);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["movie_id"] = new SelectList(_context.movies, "id", "name", schedule.movie_id);
            ViewData["room_id"]  = new SelectList(_context.rooms, "id", "name", schedule.room_id);
            return(View(schedule));
        }
Пример #11
0
        public async Task <IActionResult> Create([Bind("id,branch_id,name,status")] Room room)
        {
            if (ModelState.IsValid)
            {
                SetNotification("Created success !");
                _context.Add(room);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            SetNotification("Created fail !");
            ViewData["branch_id"] = new SelectList(_context.branches, "id", "address", room.branch_id);
            return(View(room));
        }
Пример #12
0
        public async Task <IActionResult> Create([Bind("id,name,summery,poster,trailer_path,status,duration,published_date")] Movie movie)
        {
            if (ModelState.IsValid)
            {
                string str = movie.trailer_path;
                if (movie.trailer_path != null)
                {
                    str = str.Substring(str.IndexOf("=") + 1);
                }
                movie.trailer_path = str;
                _context.Add(movie);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(movie));
        }
Пример #13
0
        public async Task <IActionResult> Create([Bind("id,username,password,displayname,email,birthday,avatar,rule")] User user, IFormFile ful)
        {
            if (ModelState.IsValid)
            {
                _context.Add(user);
                await _context.SaveChangesAsync();

                string path = Path.Combine(
                    Directory.GetCurrentDirectory(), "wwwroot/Admin/assets/images/user",
                    user.id + "." + ful.FileName.Split(".")[ful.FileName.Split(".").Length - 1]
                    );
                using (var stream = new FileStream(path, FileMode.Create))
                {
                    await ful.CopyToAsync(stream);
                }
                user.avatar = user.id + "." + ful.FileName.Split(".")[ful.FileName.Split(".").Length - 1];
                _context.Update(user);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(user));
        }
Пример #14
0
        public async Task <IActionResult> Create([Bind("id,name,image")] Actor actor, IFormFile ful)
        {
            if (ModelState.IsValid)
            {
                _context.Add(actor);
                await _context.SaveChangesAsync();

                string path = Path.Combine(
                    Directory.GetCurrentDirectory(), "wwwroot/Admin/assets/images/actor",
                    actor.id + "." + ful.FileName.Split(".")[ful.FileName.Split(".").Length - 1]
                    );
                using (var stream = new FileStream(path, FileMode.Create))
                {
                    await ful.CopyToAsync(stream);
                }
                actor.image = actor.id + "." + ful.FileName.Split(".")[ful.FileName.Split(".").Length - 1];
                _context.Update(actor);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(actor));
        }
Пример #15
0
        public async Task <IActionResult> SignUp(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var allUser = _context.users.ToList();
                foreach (var item in allUser)
                {
                    if (item.username == model.username)
                    {
                        SetAlert("User already existed in system", "warning");
                        return(View(model));
                    }
                }
                var m_username = model.username.Trim().Length;
                if (m_username <= 5 || m_username > 32)
                {
                    ModelState.AddModelError("", "User name must be between 6 - 32 character.");
                    SetAlert("Username invalid", "warning");
                    return(View(model));
                }
                var m_pwd     = model.password.Trim();
                var valid_pwd = ValidatePassword(m_pwd);
                if (valid_pwd.Count != 0)
                {
                    foreach (var item in valid_pwd)
                    {
                        if (item == -1)
                        {
                            ModelState.AddModelError("", "Password must be between 8-32 character.");
                        }
                        else if (item == -2)
                        {
                            ModelState.AddModelError("", "Password must have least one uppercase letter.");
                        }
                        else if (item == -3)
                        {
                            ModelState.AddModelError("", "Password must have least one lowercase letter.");
                        }
                        else if (item == -4)
                        {
                            ModelState.AddModelError("", "Password must have least one number.");
                        }
                        else if (item == -5)
                        {
                            ModelState.AddModelError("", "Password must have least one special letter.");
                        }
                    }
                    SetAlert("Password invalid", "warning");
                    return(View(model));
                }
                var user = new User
                {
                    username    = model.username,
                    displayname = model.username,
                    email       = model.email,
                    password    = StringProcessing.CreateMD5Hash(model.password),
                    rule        = 0
                };

                _context.Add <User>(user);
                await _context.SaveChangesAsync();

                var str = JsonConvert.SerializeObject(user);
                HttpContext.Session.SetString("user", str);
                SetAlert("Sign up success", "success");
                return(RedirectToAction("Index", "Home"));
            }

            SetAlert("Register fail", "danger");
            return(View(model));
        }