コード例 #1
0
ファイル: UsersController.cs プロジェクト: itay1996g/Shop4U
        public async Task <IActionResult> Create([Bind("UID,user_email,user_fullname,user_password,user_phone,user_city,Role,user_gender,birth_year")] Users users)
        {
            try
            {
                if (IsAdmin())
                {
                    users.CreatedDate = System.DateTime.Now;
                    if (ModelState.IsValid)
                    {
                        _context.Add(users);
                        await _context.SaveChangesAsync();

                        return(RedirectToAction(nameof(Index)));
                    }
                    return(View(users));
                }
                else
                {
                    return(RedirectToAction("Login", "Home"));
                }
            }
            catch
            {
                return(RedirectToAction("Login", "Home"));
            }
        }
コード例 #2
0
        public async Task <IActionResult> Create([Bind("branch_Id,branch_name,branch_address,branch_owner,branch_lat,branch_lng")] Branches branches)
        {
            try
            {
                if (IsAdminOrSupplier())
                {
                    if (ModelState.IsValid)
                    {
                        _context.Add(branches);
                        await _context.SaveChangesAsync();

                        return(RedirectToAction(nameof(Index)));
                    }
                    return(View(branches));
                }
                else
                {
                    return(RedirectToAction("Login", "Home"));
                }
            }
            catch
            {
                return(RedirectToAction("Login", "Home"));
            }
        }
コード例 #3
0
        public async Task <IActionResult> Create([Bind("product_Id,product_branch,product_name,product_description,product_category,Taken,TakenDate,buyer_name,product_image,product_color,ReleaseDate")] Products products, IFormFile product_image)
        {
            try
            {
                if (IsAdminOrSupplier())
                {
                    products.ReleaseDate = System.DateTime.Now;
                    //products.Taken = false;


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



                        if (product_image != null)
                        {
                            if (product_image.Length != 0)
                            {
                                FileInfo fi          = new FileInfo(product_image.FileName);
                                var      newFilename = products.product_Id + "_" + String.Format("{0:d}", (DateTime.Now.Ticks / 10) % 100000000) + fi.Extension;
                                var      webPath     = hostingEnvironment.WebRootPath;
                                var      path        = Path.Combine("", webPath + @"\ImageFiles\" + newFilename);
                                var      pathToSave  = @"/ImageFiles/" + newFilename;
                                using (var stream = new FileStream(path, FileMode.Create))
                                {
                                    await product_image.CopyToAsync(stream);
                                }
                                products.product_image = pathToSave;
                                _context.Update(products);
                                await _context.SaveChangesAsync();
                            }
                        }


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

                    return(View(products));
                }
                else
                {
                    return(RedirectToAction("Login", "Home"));
                }
            }
            catch
            {
                return(RedirectToAction("Login", "Home"));
            }
        }
コード例 #4
0
        public async Task <IActionResult> Create([Bind("UID,user_email,user_fullname,user_password,user_phone,user_city,Role,user_gender,birth_year")] Users users)
        {
            if (ModelState.IsValid)
            {
                users.CreatedDate = System.DateTime.Now;
                users.Role        = "User";
                _context.Add(users);
                await _context.SaveChangesAsync();

                //HttpContext.Session.SetString("Role", users.Role.ToString());
                //HttpContext.Session.SetString("Fullname", users.user_fullname.ToString());
                //HttpContext.Session.SetInt32("UID", users.UID);
                //HttpContext.Session.SetString("Role", users.Role.ToString());



                return(RedirectToAction(nameof(RegisterSuccess)));
            }
            return(View(users));
        }