public async Task <IActionResult> Create(SnackInfoViewModels snackInfoViewModels)
        {
            int num = snackInfoViewModels.SnackInfo.SnackNum;



            if (ModelState.IsValid)
            {
                string file_name = $"{snackInfoViewModels.SnackInfo.SnackNum}_{DateTime.Now.ToString("yyyymmddHHmmss")}.jpg";
                using (var fileStream = new FileStream(Path.Combine(_dir, file_name), FileMode.Create, FileAccess.Write))
                {
                    snackInfoViewModels.FormFile.CopyTo(fileStream);
                }
                snackInfoViewModels.SnackInfo.ImgUrl = relative_path + file_name;
                long category_id = _context.SnackCategory.FirstOrDefault(c => c.CategoryName == snackInfoViewModels.CategoryName).CategoryNum;
                snackInfoViewModels.SnackInfo.CategoryId = category_id;
                snackInfoViewModels.SnackInfo.CreateTime = DateTime.Now;
                _context.Add(snackInfoViewModels.SnackInfo);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }

            return(View(snackInfoViewModels));
        }
Esempio n. 2
0
        public async Task <IActionResult> Create([Bind("Id,CardCode,SecretKey,UserAccount,CardStatus,Price")] prepaidCard prepaidCard)
        {
            if (ModelState.IsValid)
            {
                _context.Add(prepaidCard);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(prepaidCard));
        }
        public async Task <IActionResult> Create([Bind("Id,UserAccount,Password,Money,Phone,Address")] User user)
        {
            if (ModelState.IsValid)
            {
                user.PaySecret = "123456";
                _context.Add(user);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(user));
        }
        public async Task <IActionResult> Create([Bind("Id,CategoryNum,CategoryName,Description,Status")] SnackCategory snackCategory)
        {
            if (ModelState.IsValid)
            {
                _context.Add(snackCategory);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            CategoryViewModels categoryViewModels = new CategoryViewModels()
            {
                AdminName     = GetSession("username"),
                SnackCategory = snackCategory
            };

            return(View(categoryViewModels));
        }
Esempio n. 5
0
        public async Task <bool> Create(string account, string password, string name, int permission)
        {
            Admin admin = new Admin()
            {
                LoginAccount = account,
                PassWord     = PassWordHelper.Md532Salt(password, account),
                AdminName    = name,
                Permissions  = permission,
                CreateTime   = DateTime.Now
            };

            if (ModelState.IsValid)
            {
                _context.Add(admin);
                await _context.SaveChangesAsync();

                return(true);
            }

            return(false);
        }