Ejemplo n.º 1
0
        public async Task <ActionResult> ResetPassword(EmailPasswordModel model)
        {
            if (ModelState.IsValid)
            {
                model.UserContext = WeedHackersContext.Users.Single(u => u.Email == model.Email);
                string base64GuidPassword = Convert.ToBase64String(Guid.NewGuid().ToByteArray());//New Password assigned, User can later go and change it
                model.UserContext.Password = base64GuidPassword;
                WeedHackersContext.Users.AddOrUpdate(model.UserContext);
                await WeedHackersContext.SaveChangesAsync();

                var SendNewPassword = new EmailHelper();
                await SendNewPassword.SendEmail(new EmailFormModel
                {
                    Message =
                        "Your New Default password is  " + model.UserContext.Password +
                        "  please use this to login and then update your password to your prefered new password",
                    Recipient = model.UserContext.Email
                });

                FlashMessage.Confirmation("Forgot Password", "Your password has been reset. An email was sent to you containing your new password.");
                return(RedirectToAction("Index", "Security"));
            }

            return(RedirectToAction("Index", "ForgotPassword"));
        }
Ejemplo n.º 2
0
        public async Task <ActionResult> UpdateDetails(CustomerInformationModel model)
        {
            HttpCookie WeedHackSesh    = System.Web.HttpContext.Current.Request.Cookies["WeedHackersSession"];
            var        UserDetails     = MvcApplication.Sessions[WeedHackSesh.Value].User;
            var        CustomerDetails = WeedHackersContext.Customers.ToList().Find(u => u.Id == UserDetails.Id);

            if (ModelState.IsValid)
            {
                var cryptionHelper = new FrostAura.Dynamics.Core.Helpers.FaCryptographyHelper();
                UserDetails.Email = model.email;
                if (model.password == "")
                {
                    UserDetails.Password = UserDetails.Password;
                }
                UserDetails.Password    = cryptionHelper.HashString(model.password);
                UserDetails.PhoneNumber = model.phonenumber;
                CustomerDetails.Address = model.Address;

                WeedHackersContext.Users.AddOrUpdate(u => u.Id, UserDetails);
                WeedHackersContext.Customers.AddOrUpdate(c => c.Id, CustomerDetails);

                await WeedHackersContext.SaveChangesAsync();

                FlashMessage.Confirmation("Profile Information", "Your information has been updated.");
                return(RedirectToAction("Index"));
            }
            ModelState.AddModelError("Email", "Could not update details!");
            FlashMessage.Danger("Update Unsuccessful", "We could not update your profile. Please ensure you have filled out your new details correctly and try again.");
            return(View("CustomerProfile", model));
            //===============================================================
        }
Ejemplo n.º 3
0
        public async Task <ActionResult> QuoteDecline(int Id)
        {
            var WeedHackSesh   = System.Web.HttpContext.Current.Request.Cookies["WeedHackersSession"].Value;
            var UserDetails    = MvcApplication.Sessions[WeedHackSesh].User;
            var serviceRequest = WeedHackersContext.ServiceRequests
                                 .Include(sa => sa.ServiceAdvisor.User)
                                 .Single(sr => sr.Id == Id);

            var emailmodel = new EmailFormModel
            {
                Message   = UserDetails.Name + " " + UserDetails.Surname + " has declined Quote #" + serviceRequest.Id + " issued to him <br/>",
                Recipient = serviceRequest.ServiceAdvisor.User.Email
            };

            var ServiceRequestStatus = new ServiceRequestStatusUpdate
            {
                ServiceRequestId = serviceRequest.Id,
                ServiceStatusId  = WeedHackersContext.ServiceStatuses.Single(s => s.Name == "Rejected").Id,
                Message          = "Service Requested has been rejected",
            };

            WeedHackersContext.ServiceRequests.AddOrUpdate(sr => sr.Id, serviceRequest);
            WeedHackersContext.ServiceRequestStatusUpdates.Add(ServiceRequestStatus);

            await WeedHackersContext.SaveChangesAsync();

            var email = new EmailHelper();
            await email.SendEmail(emailmodel);

            FlashMessage.Confirmation("Quote Rejected", "");
            return(RedirectToAction("QuotesReceived", "Customer"));
        }
Ejemplo n.º 4
0
        public async Task <ActionResult> AssignEmployeedToQuote(ManagerQuoteManagmentModel request)
        {
            var serviceRequest = await WeedHackersContext
                                 .ServiceRequests
                                 .SingleAsync(sr => sr.Id == request.ServiceRequest.Id);

            serviceRequest.LeadEmployeeId = request.ServiceRequest.LeadEmployeeId;

            foreach (int requestAssignedEmployeeId in request.AssignedEmployeeIds)
            {
                serviceRequest.AssignedEmployees.Add(await WeedHackersContext.Employees.SingleAsync(e => e.Id == requestAssignedEmployeeId));
            }

            WeedHackersContext.ServiceRequests.AddOrUpdate(sr => sr.Id, serviceRequest);
            var serviceStatus = await WeedHackersContext.ServiceStatuses.SingleAsync(ss => ss.Name == "In Progress");

            var serviceStatusUpdate = new ServiceRequestStatusUpdate
            {
                ServiceRequestId = serviceRequest.Id,
                Message          = "The Job is assigned and is in progress",
                ServiceStatusId  = serviceStatus.Id
            };


            WeedHackersContext.ServiceRequestStatusUpdates.Add(serviceStatusUpdate);
            await WeedHackersContext.SaveChangesAsync();

            return(RedirectToAction("QuotesManagement", new { Id = request.ServiceRequest.Id }));
        }
Ejemplo n.º 5
0
        public async Task <ActionResult> UpdateDetails(EmployeeInformationModel model)
        {
            HttpCookie WeedHackSesh    = System.Web.HttpContext.Current.Request.Cookies["WeedHackersSession"];
            var        UserDetails     = MvcApplication.Sessions[WeedHackSesh.Value].User;
            var        EmployeeDetails = WeedHackersContext.Employees.ToList().Find(u => u.Id == UserDetails.Id);

            if (ModelState.IsValid)
            {
                var cryptionHelper = new FrostAura.Dynamics.Core.Helpers.FaCryptographyHelper();

                if (model.email == null)
                {
                    model.email = UserDetails.Email;
                }
                UserDetails.Email = model.email;

                if (model.password == null)
                {
                    model.password = UserDetails.Password;
                }
                UserDetails.Password = cryptionHelper.HashString(model.password);

                if (model.phonenumber == null)
                {
                    model.phonenumber = UserDetails.PhoneNumber;
                }
                UserDetails.PhoneNumber = model.phonenumber;


                WeedHackersContext.Users.AddOrUpdate(u => u.Id, UserDetails);
                WeedHackersContext.Employees.AddOrUpdate(c => c.Id, EmployeeDetails);

                await WeedHackersContext.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            ModelState.AddModelError(model.phonenumber, "Could not add!");
            FlashMessage.Danger("Update Unsuccessful", "We could not update your profile. Please ensure you have filled out your new details correctly and try again.");
            if (EmployeeDetails.EmployeeType.Name == "Employee")
            {
                return(RedirectToAction("EmployeeHome"));
            }
            else if (EmployeeDetails.EmployeeType.Name == "Manager")
            {
                return(RedirectToAction("ManagerHome"));
            }
            else
            {
                return(RedirectToAction("Index"));
            }

            //===============================================================
        }
Ejemplo n.º 6
0
        public async Task <ActionResult> NewEmployee(AdminModel model)
        {
            model.AllDepartments   = WeedHackersContext.Departments.ToList();
            model.AllEmployeeTypes = WeedHackersContext.EmployeeTypes.ToList();
            var cryptionHelper = new FrostAura.Dynamics.Core.Helpers.FaCryptographyHelper();

            var userCheck = WeedHackersContext.Users.ToList().Find(u => u.Email == model.NewUser.Email);

            if (ModelState.IsValid)
            {
                if (userCheck != null)
                {
                    ModelState.AddModelError("Email", "Email already exists! Please use a different email address");
                    FlashMessage.Danger("Invalid Email", "Email already exists! Please use a different email address");
                    return(View("AddEmployee", model));
                }
                var UserEmp = new User
                {
                    Name        = model.NewUser.Name,
                    Surname     = model.NewUser.Surname,
                    Email       = model.NewUser.Email,
                    Password    = cryptionHelper.HashString(model.NewUser.Password),
                    PhoneNumber = model.NewUser.PhoneNumber,
                    SuperAdmin  = false,
                    Deleted     = false
                };
                var newEmployee = new WeedHackers_Data.Entities.Employee
                {
                    Id             = UserEmp.Id,
                    EmployeeTypeId = model.NewEmployee.EmployeeTypeId,
                    DepartmentId   = model.NewEmployee.DepartmentId,
                    Deleted        = false,
                    Timestamp      = DateTime.Now
                };

                WeedHackersContext.Users.Add(UserEmp);
                WeedHackersContext.Employees.Add(newEmployee);
                await WeedHackersContext.SaveChangesAsync();

                return(RedirectToAction("AllEmployees"));
            }
            ModelState.AddModelError("Name", "The Registration process could not be completed! Please ensure you have filled out the form correctly and try again");
            FlashMessage.Danger("Name", "The Registration process could not be completed! Please ensure you have filled out the form correctly and try again");
            return(View("AddEmployee", model));
        }
Ejemplo n.º 7
0
        public async Task <ActionResult> RequestService(CustomerInformationModel model)
        {
            var WeedHackSesh    = System.Web.HttpContext.Current.Request.Cookies["WeedHackersSession"].Value;
            var UserDetails     = MvcApplication.Sessions[WeedHackSesh].User;
            var CustomerDetails = WeedHackersContext.Customers.ToList().Find(u => u.Id == UserDetails.Id);
            ServiceRequestStatusUpdate ServiceRequestStatus;

            CustomerDetails.Address = model.Address;

            WeedHackersContext.Customers.AddOrUpdate(c => c.Id, CustomerDetails);

            if (ModelState.IsValid)
            {
                model.ServiceRequestModel.ServiceRequest.CustomerId = CustomerDetails.Id;

                WeedHackersContext.ServiceRequests.Add(model.ServiceRequestModel.ServiceRequest);
                ServiceRequestStatus = new ServiceRequestStatusUpdate
                {
                    ServiceRequestId = model.ServiceRequestModel.ServiceRequest.Id,
                    ServiceStatusId  = WeedHackersContext.ServiceStatuses.Single(s => s.Name == "Created").Id,
                    Message          = "Service Requested has been created",
                };
                WeedHackersContext.ServiceRequestStatusUpdates.Add(ServiceRequestStatus);
                // Magic
                WeedHackers_Data.Entities.Service service =
                    WeedHackersContext
                    .Services
                    .Single(s => s.Id == model.ServiceRequestModel.ServiceRequest.ServiceId);

                var assigningEmployee = WeedHackersContext
                                        .Employees
                                        .Include(e => e.EmployeeType)
                                        .Where(e => e.DepartmentId == service.DepartmentId && e.EmployeeType.Name == "Service Advisor")
                                        .Include(e => e.AssignedServiceRequests)
                                        .OrderByDescending(e => e.AssignedServiceRequests.Count)
                                        .First();

                model.ServiceRequestModel.ServiceRequest.ServiceAdvisorId = assigningEmployee.Id;

                await WeedHackersContext.SaveChangesAsync();
            }
            FlashMessage.Confirmation("Service Requested", "Your service has successfully been requested and is awaiting inspection.");
            return(RedirectToAction("Index", "Customer"));
        }
Ejemplo n.º 8
0
        public async Task <ActionResult> Register(CustomerRegistrationModel model)
        {
            var cryptionHelper = new FrostAura.Dynamics.Core.Helpers.FaCryptographyHelper();

            if (ModelState.IsValid)
            {
                var existingUser = WeedHackersContext.Users.FirstOrDefault(u => u.Email == model.RegistringUser.Email);
                if (existingUser != null)
                {
                    ModelState.AddModelError("Email", "Email already registered");
                    FlashMessage.Danger("{0} is already registered. Please use a different valid email address to register", model.RegistringUser.Email);
                }

                var User = new User
                {
                    Name        = model.RegistringUser.Name,
                    Surname     = model.RegistringUser.Surname,
                    Email       = model.RegistringUser.Email,
                    Password    = cryptionHelper.HashString(model.RegistringUser.Password),
                    PhoneNumber = model.RegistringUser.PhoneNumber,
                    Deleted     = false,
                    Timestamp   = DateTime.Now,
                    SuperAdmin  = false
                };
                WeedHackersContext.Users.Add(User);

                var Customer = new WeedHackers_Data.Entities.Customer
                {
                    Id             = User.Id,
                    Address        = model.RegistringCustomer.Address,
                    CustomerTypeId = model.RegistringCustomer.CustomerTypeId,
                    EmailVerified  = false
                };
                WeedHackersContext.Customers.Add(Customer);

                await WeedHackersContext.SaveChangesAsync();

                var userContext = await WeedHackersContext
                                  .Users
                                  .Include(u => u.Customer.CustomerType)
                                  .Include(u => u.Customer)
                                  .SingleOrDefaultAsync(u => u.Id == model.RegistringUser.Id);

                // Create the session
                var session = new SessionModel
                {
                    Identifier = Guid.NewGuid(),             // Session unique identifier (This gets sent to the client)
                    User       = userContext,                // The mandatory user object a session belongs to
                    ExpiryTime = DateTime.Now.AddMinutes(20) // Session valid for 20 minutes
                };

                // Store the session on the server (As opposed to the database)
                MvcApplication.Sessions[session.Identifier.ToString()] = session;

                // Pass the session to the client via cookies (like before)
                var sessionCookie = new HttpCookie("WeedHackersSession")
                {
                    Value    = session.Identifier.ToString(),
                    Expires  = session.ExpiryTime,
                    HttpOnly = true
                };

                Response.Cookies.Add(sessionCookie);

                //var userContext = (User)ViewBag.UserContext;
                FlashMessage.Confirmation("Registration Successful!", "Welcome to WeedHackers {0}", model.RegistringUser.Name);
                return(RedirectToAction("Index", "Home"));
            }
            else
            {
                ModelState.AddModelError("", "Please fill in all fields and try again");
                FlashMessage.Danger("Error", "Please fill in all fields and try again");
                return(View("Index", model));
            }
        }
Ejemplo n.º 9
0
        public async Task <ActionResult> SendQuote(InspectionModel model)
        {
            EmailHelper send = new EmailHelper();

            try
            {
                var dbServiceRequest = await WeedHackersContext
                                       .ServiceRequests
                                       .Include(ct => ct.Customer.CustomerType)
                                       .Include(ct => ct.Customer.User)
                                       .Include(s => s.Service)
                                       .Include(d => d.Service.Department)
                                       .Include(d => d.ServiceAdvisor.User)
                                       .Include(ss => ss.ServiceRequestStatusUpdates.Select(srsu => srsu.ServiceStatus))
                                       .SingleAsync(s => s.Id == model.ServiceRequest.ServiceRequest.Id);


                double subtotal = dbServiceRequest.Service.PricePerUnit *
                                  (double)model.ServiceRequest.ServiceRequest.UnitQuantity;
                double Total = subtotal * 1.14;
                dbServiceRequest.UnitQuantity = model.ServiceRequest.ServiceRequest.UnitQuantity;

                var serviceStatus = await WeedHackersContext.ServiceStatuses.SingleAsync(ss => ss.Name == "Inspected");

                ServiceRequestStatusUpdate serviceRequestStatusUpdate = new ServiceRequestStatusUpdate
                {
                    ServiceRequestId = dbServiceRequest.Id,
                    ServiceStatusId  = serviceStatus.Id,
                    Message          = "Service Request has been Inspected."
                };


                WeedHackersContext.ServiceRequestStatusUpdates.Add(serviceRequestStatusUpdate);
                await WeedHackersContext.SaveChangesAsync();

                var emailRequest = new EmailQuoteModel();

                emailRequest.Email           = dbServiceRequest.ServiceAdvisor.User.Email;
                emailRequest.QuotationNumber = dbServiceRequest.Id.ToString();
                emailRequest.ServiceType     = dbServiceRequest.Service.ServiceName;
                emailRequest.Tell            = dbServiceRequest.ServiceAdvisor.User.PhoneNumber;
                emailRequest.UnitQuantity    = dbServiceRequest.UnitQuantity.ToString();
                emailRequest.UnitPrice       = dbServiceRequest.Service.PricePerUnit.ToString("R0.00");
                emailRequest.UnitSubtotal    = subtotal.ToString("R0.00");
                emailRequest.UnitTotal       = Total.ToString("R0.00");
                emailRequest.EmailFormModel  = new EmailFormModel
                {
                    Recipient = dbServiceRequest.Customer.User.Email,
                    Message   = ""
                };

                await send.SendQuotationEmail(emailRequest);

                FlashMessage.Confirmation("Inspection Complete", "Quote of inspection has been sent to the customer.");
                return(RedirectToAction("Index", "Employee"));
            }
            catch (Exception)
            {
                FlashMessage.Danger("Inspection Error", "There was a problem processing the inspection.");
                return(View("Index"));
            }
        }