public IActionResult Register([Bind("Name,Email,Password,Phone,Total_Spending,Status")] Customer customer)
 {
     if (ModelState.IsValid)
     {
         customer.Password = StringProcessing.CreateMD5(customer.Password);
         _context.Add(customer);
         _context.SaveChangesAsync();
         return(View("Index"));
     }
     return(View("Index"));
 }
Esempio n. 2
0
        public async Task <IActionResult> Create([Bind("ID,Name,Email,Password,Avatar,Phone,Address,Status")] Staf staf, IFormFile ful)
        {
            Middleware.CheckStafLogin(HttpContext);
            if (ModelState.IsValid)
            {
                staf.Password = StringProcessing.CreateMD5(staf.Password);
                _context.Add(staf);
                await _context.SaveChangesAsync();

                var tenImg = staf.ID + "." + ful.FileName.Split(".")[ful.FileName.Split(".").Length - 1];
                var path   = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/Uploads/Staf", tenImg);
                using (var stream = new FileStream(path, FileMode.Create))
                {
                    await ful.CopyToAsync(stream);
                }
                staf.Avatar = tenImg;
                _context.Update(staf);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(staf));
        }
        public IActionResult Login([Bind("Name,Email,Password,Avatar,Phone,Address,Status")] Staf staf)
        {
            var login = _context.Stafs.Where(s => (s.Email.Equals(staf.Email) && s.Password.Equals(StringProcessing.CreateMD5(staf.Password))));

            if (login.ToList().Count == 0)
            {
                return(View("Index"));
            }
            var str = JsonConvert.SerializeObject(login.First());

            HttpContext.Session.SetString("staf", str);
            return(Redirect("/Admin/Home/Index"));
        }
        public IActionResult Login([Bind("Name,Email,Password,Phone,Total_Spending,Status")] Customer customer)
        {
            var login = _context.Customers.Where(s => (s.Email.Equals(customer.Email) && s.Password.Equals(StringProcessing.CreateMD5(customer.Password))));

            if (login.ToList().Count == 0)
            {
                return(View("Index"));
            }
            var str = JsonConvert.SerializeObject(login.First());

            HttpContext.Session.SetString("customer", str);
            return(Redirect("/"));
        }