示例#1
0
        public IActionResult Create(Customer customer, IFormFile postedFile)
        {
            if (postedFile != null && postedFile.Length > 0) //arquivo não está vazio
            {
                string wwwPath     = this.Environment.WebRootPath;
                string contentPath = this.Environment.ContentRootPath;

                string path = Path.Combine(this.Environment.WebRootPath, "Uploads");
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }

                string fileName = Path.GetFileName(postedFile.FileName);
                using (FileStream stream = new FileStream(Path.Combine(path, fileName), FileMode.Create))
                {
                    postedFile.CopyTo(stream);
                    customer.Picture = fileName;
                }
            }
            DAL.AppContext appContext = new DAL.AppContext();
            customer.Salt = Guid.NewGuid().ToString();
            customer.Hash = Util.Cryptography.CreateMD5(customer.Hash + customer.Salt);
            appContext.Customers.Add(customer);
            appContext.SaveChanges();
            return(RedirectToAction("Index", "Home"));
        }
示例#2
0
        public IActionResult Index(Customer customer)
        {
            DAL.AppContext appContext       = new DAL.AppContext();
            Customer       customerDatabase = appContext.Customers
                                              .Where(x => x.Email == customer.Email).SingleOrDefault();

            if (customerDatabase == null)
            {
                ViewBag.Error = "Usuário ou senha incorretos!";
                return(View(customer));
            }
            else
            {
                string hash = customer.Hash + customerDatabase.Salt;
                hash = Util.Cryptography.CreateMD5(hash);
                if (customerDatabase.Hash == hash)
                {
                    HttpContext.Session.SetString("user", customerDatabase.Name);
                    HttpContext.Session.SetInt32("userId", customerDatabase.Id);
                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    ViewBag.Error = "Usuário ou senha incorretos!";
                    return(View(customer));
                }
            }
        }
示例#3
0
        public IActionResult Detail(int id)
        {
            DAL.AppContext context = new DAL.AppContext();
            Product        product = context.Products.Find(id);

            return(View(product));
        }
示例#4
0
        //public IActionResult Index(int? cardapiosId)
        //{
        //    DAL.AppContext contexto = new DAL.AppContext();
        //    IEnumerable<Cardapios> lsCardapios = contexto.Cardapios;
        //    if (cardapiosId.HasValue)
        //    {
        //        lsCardapios = lsCardapios.Where(x => x.Id == cardapiosId.Value);
        //    }
        //    lsCardapios = lsCardapios.OrderBy(x => x.Id).ToList();
        //    ViewBag.Cardapios = contexto.Cardapios.OrderBy(x => x.Id).ToList();
        //    return View(lsCardapios);
        //}

        public IActionResult Index()
        {
            DAL.AppContext context = new DAL.AppContext();
            Cardapios      prato   = context.Cardapios.Find();

            return(View(prato));
        }
示例#5
0
        public IActionResult Index(int?categoryId)
        {
            DAL.AppContext        contexto   = new DAL.AppContext();
            IEnumerable <Product> lsProducts = contexto.Products;

            if (categoryId.HasValue)
            {
                lsProducts = lsProducts.Where(x => x.CategoryId == categoryId.Value);
            }
            lsProducts         = lsProducts.OrderBy(x => x.Name).ToList();
            ViewBag.Categories = contexto.Categories.OrderBy(x => x.Name).ToList();
            return(View(lsProducts));
        }