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"));
            }
        }
Esempio n. 2
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"));
            }
        }
Esempio n. 3
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);
        }
Esempio n. 4
0
        public async Task <IActionResult> Edit(int id, [Bind("UID,user_email,user_fullname,user_password,user_phone,user_city,CreatedDate,Role,user_gender,birth_year")] Users users)
        {
            try
            {
                if (IsAdmin())
                {
                    if (id != users.UID)
                    {
                        return(RedirectToAction("Login", "Home"));
                    }

                    if (ModelState.IsValid)
                    {
                        try
                        {
                            _context.Update(users);
                            await _context.SaveChangesAsync();
                        }
                        catch (DbUpdateConcurrencyException)
                        {
                            if (!UsersExists(users.UID))
                            {
                                return(RedirectToAction("Login", "Home"));
                            }
                            else
                            {
                                throw;
                            }
                        }
                        return(RedirectToAction(nameof(Index)));
                    }
                    return(View(users));
                }
                else
                {
                    return(RedirectToAction("Login", "Home"));
                }
            }
            catch
            {
                return(RedirectToAction("Login", "Home"));
            }
        }
Esempio n. 5
0
        public async Task <IActionResult> Edit(int id, [Bind("branch_Id,branch_name,branch_address,branch_owner,branch_lat,branch_lng")] Branches branches)
        {
            try
            {
                if (IsAdminOrSupplier())
                {
                    if (id != branches.branch_Id)
                    {
                        return(RedirectToAction("Login", "Home"));
                    }

                    if (ModelState.IsValid)
                    {
                        try
                        {
                            _context.Update(branches);
                            await _context.SaveChangesAsync();
                        }
                        catch (DbUpdateConcurrencyException)
                        {
                            if (!BranchesExists(branches.branch_Id))
                            {
                                return(RedirectToAction("Login", "Home"));
                            }
                            else
                            {
                                throw;
                            }
                        }
                        return(RedirectToAction(nameof(Index)));
                    }
                    return(View(branches));
                }
                else
                {
                    return(RedirectToAction("Login", "Home"));
                }
            }
            catch
            {
                return(RedirectToAction("Login", "Home"));
            }
        }