Example #1
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)
        {
            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"));
            }
        }
Example #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"));
            }
        }
        public async Task <IActionResult> ClaimConfirmed(int?id)
        {
            if (IsUser())
            {
                if (id == null)
                {
                    return(RedirectToAction("Login", "Home"));
                }


                var products = await _context.Products.FindAsync(id);

                products.Taken      = true;
                products.buyer_name = HttpContext.Session.GetString("Fullname");
                products.TakenDate  = System.DateTime.Now.Date.ToString("dd/MM/yyyy");
                products.UID        = HttpContext.Session.GetInt32("UID");
                _context.Update(products);
                await _context.SaveChangesAsync();



                return(RedirectToAction("ThankYouOrder", new { id = id }));
            }
            else
            {
                return(RedirectToAction("Login", "Home"));
            }
        }
Example #4
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"));
            }
        }
Example #5
0
        public async Task<IActionResult> PersonalDetailsEdit([Bind("UID,user_email,user_password,user_fullname,user_phone,user_city,Role,user_gender,CreatedDate,birth_year")] Users users)
        {

                                 
            var id = HttpContext.Session.GetInt32("UID");

            if (id == null || id != users.UID)
            {
                return RedirectToAction("Login", "Home");
            }

            
            if(HttpContext.Session.GetString("Role") == "User")
            {

                users.Role = "User";

            }


            if (HttpContext.Session.GetString("Role") == "Supplier")
            {

                users.Role = "Supplier";

            }

            if (HttpContext.Session.GetString("Role") == "Admin")
            {
                users.Role = "Admin";

            }



            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(users);
                    await _context.SaveChangesAsync();
                    return RedirectToAction("PersonalDetails", "Account");
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!UsersExists(users.UID))
                    {
                        return RedirectToAction("Login", "Home");
                    }
                    else
                    {
                        throw;
                    }
                }
            }
            return View(users);
        }
Example #6
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));
        }