예제 #1
0
        public async Task <IActionResult> Create([Bind("EmployeeId,Email,Password,FirstName,LastName")] Employees employees, string Password2)
        {
            if (HttpContext.Session.GetString("userType") == "admin")
            {
                if (ModelState.IsValid)
                {
                    //validate email and password
                    var emailValid    = UniqueEmail(employees.Email);
                    var passwordValid = ValidatePassword(employees.Password);

                    if (String.IsNullOrEmpty(employees.Password) || String.IsNullOrEmpty(Password2))
                    {
                        passwordValid = false;
                    }

                    var passwordsMatch = false;

                    if (employees.Password == Password2)
                    {
                        passwordsMatch = true;
                    }

                    if (emailValid && passwordValid && passwordsMatch)
                    {
                        _context.Add(employees);
                        await _context.SaveChangesAsync();

                        return(RedirectToAction(nameof(Index)));
                    }
                    else
                    {
                        if (!emailValid)
                        {
                            ViewBag.errorEmail = "An account with this email already exists";
                        }
                        if (!passwordValid)
                        {
                            ViewBag.errorPassword = "******";
                        }
                        if (!passwordsMatch)
                        {
                            ViewBag.errorPasswordConfirm = "Passwords don't match";
                        }
                    }
                }
                return(View(employees));
            }
            else if (HttpContext.Session.GetString("userType") == "employee")
            {
                return(View("EmployeeHomePage"));
            }
            else
            {
                return(RedirectToAction("Login", "Members"));
            }
        }
예제 #2
0
        public async Task <IActionResult> Create([Bind("OrderStatusesId,OrderId,StatusId,EmployeeId,EstimatedFinishDate,StartDate,FinishDate")] OrderStatuses orderStatuses)
        {
            if (ModelState.IsValid)
            {
                _context.Add(orderStatuses);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["EmployeeId"] = new SelectList(_context.Employees, "EmployeeId", "EmployeeId", orderStatuses.EmployeeId);
            ViewData["OrderId"]    = new SelectList(_context.Orders, "OrderId", "OrderId", orderStatuses.OrderId);
            ViewData["StatusId"]   = new SelectList(_context.Statuses, "StatusId", "StatusId", orderStatuses.StatusId);
            return(View(orderStatuses));
        }
예제 #3
0
        public async Task <IActionResult> Create([Bind("AppointmentId,MemberId,ServiceId,AppointmentDate,AppointmentTime,Description")] Appointments appointments)
        {
            if (HttpContext.Session.GetString("employeeId") != null)
            {
                if (ModelState.IsValid)
                {
                    if (DateTime.Today < appointments.AppointmentDate)
                    {
                        appointments.Approved = true;
                        _context.Add(appointments);
                        await _context.SaveChangesAsync();

                        //Email customer
                        var member = _context.Members.Where(a => a.MemberId == appointments.MemberId).FirstOrDefault();
                        var email  = member.Email;
                        var fname  = member.FirstName;
                        var lname  = member.LastName;

                        SendEmail("Created", email, fname + " " + lname, appointments.AppointmentDate, appointments.AppointmentTime);

                        return(RedirectToAction(nameof(Index)));
                    }
                    else
                    {
                        ViewBag.dateError = "Choose any date after today";
                    }
                }
                ViewData["MemberId"]  = new SelectList(_context.Members, "MemberId", "fullName", appointments.MemberId);
                ViewData["ServiceId"] = new SelectList(_context.Services, "ServiceId", "Name", appointments.ServiceId);
                //ViewData["VehicleId"] = new SelectList(_context.Vehicles.Where(a => a.MemberId == int.Parse(memberId)), "VehicleId", "fullVehicleName", appointments.VehicleId);
                return(View(appointments));
            }
            else
            {
                return(RedirectToAction("Index", "Home"));
            }
        }
예제 #4
0
        public async Task <IActionResult> Create([Bind("ServiceId,Name,Description,TimeToComplete,Cost")] Services services)
        {
            if (HttpContext.Session.GetString("employeeId") != null)
            {
                if (ModelState.IsValid)
                {
                    _context.Add(services);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
                return(View(services));
            }
            else
            {
                return(RedirectToAction("Login", "Members"));
            }
        }
예제 #5
0
        public async Task <IActionResult> Create([Bind("VehicleId,Year,Make,Model,LicensePlate,MemberId")] Vehicles vehicles)
        {
            if (HttpContext.Session.GetString("memberId") != null)
            {
                if (ModelState.IsValid)
                {
                    var memberId = HttpContext.Session.GetString("memberId");
                    vehicles.MemberId = int.Parse(memberId);

                    _context.Add(vehicles);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
                return(View(vehicles));
            }
            else
            {
                ViewBag.error = "An error occured, login again";
                return(RedirectToAction("Login", "Members"));
            }
        }
예제 #6
0
        public async Task <IActionResult> Create([Bind("OrderId,AppointmentId,OrderDate,OrderTotal,OrderDescription,Completed")] Orders orders)
        {
            if (HttpContext.Session.GetString("employeeId") != null)
            {
                if (ModelState.IsValid)
                {
                    _context.Add(orders);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
                //ViewData["AppointmentId"] = new SelectList(_context.Appointments, "AppointmentId", "AppointmentId", orders.AppointmentId);
                ViewData["AppointmentId"] = new SelectList(_context.Appointments, "AppointmentId", "ApptInfo", orders.AppointmentId);
                return(View(orders));
            }
            else if (HttpContext.Session.GetString("memberId") != null)
            {
                return(RedirectToAction("Index", "Home"));
            }
            else
            {
                return(RedirectToAction("Login", "Members"));
            }
        }
예제 #7
0
        public async Task <IActionResult> Create([Bind("MemberId,FirstName,LastName,Email,Phone,Password,DateOfBirth,Address,PostalCode,Province,City,Country")] Members members, string Password2)
        {
            if (ModelState.IsValid)
            {
                //validate
                var emailValid    = UniqueEmail(members.Email);
                var passwordValid = ValidatePassword(members.Password);
                var postalValid   = false;
                if (members.PostalCode != null)
                {
                    postalValid = ValidatePostal(members.PostalCode);
                }
                else
                {
                    postalValid = true;
                }

                if (String.IsNullOrEmpty(members.Password) || String.IsNullOrEmpty(Password2))
                {
                    passwordValid = false;
                }

                var passwordsMatch = false;

                if (members.Password == Password2)
                {
                    passwordsMatch = true;
                }

                if (emailValid && passwordValid && passwordsMatch && postalValid)
                {
                    _context.Add(members);
                    await _context.SaveChangesAsync();

                    //set user type and memberID session variables
                    HttpContext.Session.SetString("userType", "member");
                    HttpContext.Session.SetString("memberId", members.MemberId.ToString());

                    var fname = members.FirstName;
                    var lname = members.LastName;
                    HttpContext.Session.SetString("userFullName", fname + " " + lname);

                    ViewBag.memberName = members.FirstName + " " + members.LastName;

                    return(View("MemberHomePage"));
                }
                else
                {
                    if (!emailValid)
                    {
                        ViewBag.errorEmail = "An account with this email already exists";
                    }
                    if (!passwordValid)
                    {
                        ViewBag.errorPassword = "******";
                    }
                    if (!passwordsMatch)
                    {
                        ViewBag.errorPasswordConfirm = "Passwords don't match";
                    }
                    if (!postalValid)
                    {
                        ViewBag.errorPostal = "Enter correct Postal Code Format (X1X1X1)";
                    }
                }
            }
            return(View(members));
        }