コード例 #1
0
 public ActionResult ChangePassword(ChangePassword cp)
 {
     if (ModelState.IsValid)
     {
         var user = _context.Users.Where(
             x => x.UserName.Equals(User.Identity.Name) &&
             x.Password.Equals(cp.CurrentPassword))
                    .FirstOrDefault();
         if (user == null)
         {
             ModelState.AddModelError("CurrentPassword", "Current password does not match");
         }
         else if (cp.CurrentPassword.Equals(cp.NewPassword))
         {
             ModelState.AddModelError("NewPassword", "New password cannot be same as current password");
         }
         else
         {
             user.Password = cp.NewPassword;
             _context.Entry(user).State = System.Data.Entity.EntityState.Modified;
             _context.SaveChanges();
             ViewData["message"] = "Password updated successfully";
         }
     }
     return(View());
 }
コード例 #2
0
        public ActionResult Create(ChallanViewModel challanViewModel)
        {
            if (ModelState.IsValid)
            {
                foreach (Challan ch in challanViewModel.Challans)
                {
                    ch.CustomerId = challanViewModel.Customer;
                }
                _context.Challans.AddRange(challanViewModel.Challans);
                _context.SaveChanges();

                ChallanViewModel cvm = new ChallanViewModel
                {
                    Customer  = challanViewModel.Customer,
                    Customers = new SelectList(
                        _context.Customers
                        .Select(x => new { x.Id, x.Name })
                        //.OrderBy(x => x.Name)
                        .ToList(), "Id", "Name", challanViewModel.Customer),
                    Challans = _context.Challans
                               .Where(x => x.CustomerId == challanViewModel.Customer)
                               .OrderBy(x => x.ChallanDate).ToList()
                };
                return(View("Index", cvm));
            }
            else
            {
                challanViewModel.Customers = new SelectList(
                    _context.Customers
                    .Select(x => new { x.Id, x.Name })
                    .OrderBy(x => x.Name)
                    .ToList(), "Id", "Name", challanViewModel.Customer);

                return(View(challanViewModel));
            }
        }