Beispiel #1
0
        public async Task <IActionResult> Edit(int id, [Bind("CustomerId,CustomerName,NipString,ContactPerson,PhoneNumberString")] Customers customers)
        {
            if (HttpContext.Session.GetString("EditCustomers") == "false")
            {
                return(RedirectToAction("Index", "Home"));
            }
            if (id != customers.CustomerId)
            {
                return(NotFound());
            }
            if (customers.Nip < 1000000000)
            {
                ViewBag.ErrorMessage = "Niepoprawny numer NIP!";
            }
            if (customers.PhoneNumber < 100000000)
            {
                ViewBag.ErrorMessage = "Niepoprawny numer telefonu!";
            }
            if (ModelState.IsValid && ViewBag.ErrorMessage == null)
            {
                try
                {
                    _context.Update(customers);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CustomersExists(customers.CustomerId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Details), new { id = id }));
            }

            return(View(await _context.Customers.Include(c => c.Addresses).FirstOrDefaultAsync(m => m.CustomerId == id)));
        }
Beispiel #2
0
        // GET: Orders/Completed/5
        public async Task <IActionResult> Completed(int?id)
        {
            if (HttpContext.Session.GetString("EditOrders") == "false")
            {
                return(RedirectToAction("Index", "Home"));
            }
            if (id == null)
            {
                return(NotFound());
            }

            var orders = await _context.Orders.FirstOrDefaultAsync(m => m.OrderId == id);

            if (orders == null)
            {
                return(NotFound());
            }

            orders.RealisationDate = DateTime.Now;
            _context.Update(orders);
            await _context.SaveChangesAsync();

            return(RedirectToAction("Details", new { id = id }));
        }
Beispiel #3
0
        public async Task <IActionResult> Edit(int id, [Bind("TaxRateId,Rate")] TaxRates taxRates)
        {
            if (HttpContext.Session.GetString("EditProducts") == "false")
            {
                return(RedirectToAction("Index", "Home"));
            }
            if (id != taxRates.TaxRateId)
            {
                return(NotFound());
            }

            int taxRatesWithSameRate = await _context.TaxRates.Where(t => t.Rate == taxRates.Rate).CountAsync();

            if (taxRatesWithSameRate > 0)
            {
                ViewBag.ErrorMessage = "Istnieje już taka stawka VAT!";
                return(View(taxRates));
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(taxRates);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!TaxRatesExists(taxRates.TaxRateId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(taxRates));
        }
Beispiel #4
0
        public async Task <IActionResult> Edit(int id, [Bind("ProductId,ProductName,BaseNetPrice,TaxRateId")] ProductDTO product)
        {
            if (HttpContext.Session.GetString("EditProducts") == "false")
            {
                return(RedirectToAction("Index", "Home"));
            }
            if (id != product.ProductId)
            {
                return(NotFound());
            }

            var productToInsert = new Products();

            productToInsert.ProductId    = product.ProductId;
            productToInsert.ProductName  = product.ProductName;
            productToInsert.BaseNetPrice = (int)(product.BaseNetPrice * 100);
            productToInsert.TaxRateId    = product.TaxRateId;

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(productToInsert);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ProductsExists(productToInsert.ProductId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["TaxRateId"] = new SelectList(_context.TaxRates.OrderBy(tr => tr.Rate), "TaxRateId", "Rate", product.TaxRateId);
            return(View(product));
        }
Beispiel #5
0
        public async Task <IActionResult> Edit(int id, [Bind("UserId,Username,Password,Firstname,Lastname,PermLevel")] Users users)
        {
            if (HttpContext.Session.GetString("EditUsers") == "false")
            {
                return(RedirectToAction("Index", "Home"));
            }
            if (id != users.UserId)
            {
                return(NotFound());
            }

            var oldUser = await _context.Users.Where(u => u.UserId == id).AsNoTracking().FirstOrDefaultAsync();

            if (oldUser.Password != users.Password)
            {
                users.Password = PasswordHelper.HashPassword(users.Password);
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(users);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!UsersExists(users.UserId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["PermLevel"] = new SelectList(_context.UserPermissions, "PermLevel", "PermName", users.PermLevel);
            return(View(users));
        }
Beispiel #6
0
        public async Task <IActionResult> Edit(int id, [Bind("PermLevel,PermName,EditUsers,EditProducts,EditCustomers,EditOrders,EditInvoices")] UserPermissions userPermissions)
        {
            if (HttpContext.Session.GetString("EditUsers") == "false")
            {
                return(RedirectToAction("Index", "Home"));
            }
            if (id != userPermissions.PermLevel)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(userPermissions);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!UserPermissionsExists(userPermissions.PermLevel))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            var permissions = await _context.UserPermissions.ToListAsync();

            ViewBag.Permissions = permissions;

            return(View(userPermissions));
        }
Beispiel #7
0
        public async Task <IActionResult> PasswordChange([Bind("OldPassword,NewPassword,NewPasswordConfirmation")] PasswordChangeDTO passwordChange)
        {
            string userIdString = HttpContext.Session.GetString("UserId");

            if (userIdString == null)
            {
                return(NotFound());
            }
            int userId = int.Parse(userIdString);
            var user   = await _context.Users.FindAsync(userId);

            if (user == null)
            {
                return(NotFound());
            }
            if (passwordChange.OldPassword == null || passwordChange.NewPassword == null || passwordChange.NewPasswordConfirmation == null)
            {
                ViewBag.ErrorMessage            = "Musisz wypełnić wszystkie pola!";
                ViewBag.OldPassword             = "";
                ViewBag.NewPassword             = "";
                ViewBag.NewPasswordConfirmation = "";
                return(View());
            }
            ViewBag.OldPassword             = passwordChange.OldPassword;
            ViewBag.NewPassword             = passwordChange.NewPassword;
            ViewBag.NewPasswordConfirmation = passwordChange.NewPasswordConfirmation;
            string passwordInDB = user.Password;

            if (!PasswordHelper.VerifyHashedPassword(passwordInDB, passwordChange.OldPassword))
            {
                ViewBag.ErrorMessage = "Podałeś błędne hasło!";
                ViewBag.OldPassword  = "";
            }
            if (!passwordChange.NewPassword.Any(c => char.IsDigit(c)))
            {
                ViewBag.ErrorMessage = "Hasło musi zawierać przynajmniej jedną cyfrę!";
            }
            if (passwordChange.NewPassword.IndexOfAny("!@#$%^&*?_~-£().,".ToCharArray()) == -1)
            {
                ViewBag.ErrorMessage = "Nowe hasło musi zawierać przynajmniej jeden znak specjalny!";
            }
            if (!passwordChange.NewPassword.Any(c => char.IsUpper(c)))
            {
                ViewBag.ErrorMessage = "Nowe hasło musi zawierać małe i duże litery!";
            }
            if (!passwordChange.NewPassword.Any(c => char.IsLower(c)))
            {
                ViewBag.ErrorMessage = "Nowe hasło musi zawierać małe i duże litery!";
            }
            if (passwordChange.NewPassword.Length < 8)
            {
                ViewBag.ErrorMessage = "Hasło musi zawierać przynajmniej 8 znaków!";
            }
            if (passwordChange.NewPassword != passwordChange.NewPasswordConfirmation)
            {
                ViewBag.ErrorMessage            = "Podane hasła różnią się!";
                ViewBag.NewPasswordConfirmation = "";
            }
            if (ViewBag.ErrorMessage == null)
            {
                user.Password = PasswordHelper.HashPassword(passwordChange.NewPassword);
                _context.Update(user);
                await _context.SaveChangesAsync();

                return(RedirectToAction("PasswordChange", new { id = 0 }));
            }

            return(View());
        }