public ActionResult <dynamic> Register([FromBody] UserPurchase model)
        {
            try
            {
                var userId = int.Parse(User.FindFirstValue(ClaimTypes.NameIdentifier));

                model.UserId    = userId;
                model.CreatedAt = DateTime.UtcNow;

                var purchase = _purchaseService.Register(model);

                return(Ok(
                           new
                {
                    purchase = purchase,
                }
                           ));
            }
            catch (Exception e)
            {
                return(BadRequest(
                           new
                {
                    message = e.Message
                }
                           ));
            }
        }
Exemplo n.º 2
0
        public UserPurchase Register(UserPurchase purchase)
        {
            _context.UsersPurchases.Add(purchase);
            _context.SaveChanges();

            return(purchase);
        }
        public string CreateNewUser(SignUpModel model)
        {
            if (IsNewUserValid(model))
            {
                var salt = GenerateSequenceOfChars(20);
                // TODO: check facility name length
                var password = GeneratePassword(model.FacilityName);

                var user = new UserPurchase
                {
                    Email                = model.Email,
                    PasswordSalt         = salt,
                    Password             = HashPassword(password, salt),
                    FacilityName         = model.FacilityName,
                    UserRegistrationDate = DateTime.Now,
                    UserExpirationDate   = DateTime.Now.AddMonths(6)
                };

                _context.UserPurchases.Add(user);
                _context.SaveChanges();

                return(password);
            }

            return(null);
        }
        private void sendEmails(Vendor vendor, UserPurchase user, int categoryId)
        {
            MailContent vendorMailContent      = MailConfigurator.createVendorReport(vendor, user, categoryId);
            MailContent vendorAdminMailContent = MailConfigurator.createVendorAdminReport(vendor, user, categoryId);

            mailService.sendMail(vendorMailContent, true);
            mailService.sendMail(vendorAdminMailContent, true);
        }
        public static MailContent createManagerReportEmail(UserPurchase user, QuestionnaireReport report)
        {
            MailContent mailContent = new MailContent();

            mailContent.MailFrom      = adminEmail;
            mailContent.MailingAdress = adminEmail;
            mailContent.Subject       = "FSMA Self Assessment Report for " + user.FacilityName;
            return(mailContent);
        }
        public ActionResult AddUser()
        {
            UserPurchase userPurchase = new UserPurchase();
            DateTime     x            = DateTime.Now;
            DateTime     y            = x.AddMonths(6).Date;

            userPurchase.UserExpirationDate = y;
            //userPurchase.ActivatorsEmail = User.Identity.Name;
            return(View(userPurchase));
        }
 public UserPurchase Register([FromBody] UserPurchase model)
 {
     try
     {
         return(_purchaseRepository.Register(model));
     }
     catch
     {
         throw new Exception("Erro ao tentar registrar compra.");
     }
 }
        public ActionResult EditUser(UserPurchase userPurchase)
        {
            UserPurchase   temp           = _context.UserPurchases.First(x => x.Id == userPurchase.Id);
            UserRepository userRepository = new UserRepository();

            if (ModelState.IsValid)
            {
                String oldPassword = temp.Password;

                var salt = "ururu";
                var pw   = UserRepository.HashPassword(userPurchase.Password.Trim(), salt);

                //If password changed
                if (userPurchase.Password != oldPassword)
                {
                    temp.Password     = pw;
                    temp.PasswordSalt = salt;
                }

                temp.UserRegistrationDate = DateTime.Now;
                temp.UserExpirationDate   = userPurchase.UserExpirationDate;
                temp.ActivatorsEmail      = User.Identity.Name;
                temp.Name  = userPurchase.Name;
                temp.Email = userPurchase.Email.ToLower().Trim();
                if (userPurchase.ActivatorsEmail != null)
                {
                    temp.ActivatorsEmail = userPurchase.ActivatorsEmail.ToLower().Trim();
                }
                else
                {
                    temp.ActivatorsEmail = null;
                }
                temp.FacilityName = userPurchase.FacilityName;
                temp.IsAdmin      = userPurchase.IsAdmin;

                //Check to make sure the combination of Email, Password, and Facilty is unique
                int existingUserCheck = _context.UserPurchases.Where(x => x.Email == userPurchase.Email && x.Password == pw && x.FacilityName == userPurchase.FacilityName && x.Id != userPurchase.Id).Count();

                if (existingUserCheck == 0)
                {
                    _context.SaveChanges();
                    return(RedirectToAction("Index"));
                }
                else
                {
                    ModelState.AddModelError("Email", "The combination of Email, Password, and Facility Name must be unique. ");
                }
            }

            return(View(userPurchase));
        }
Exemplo n.º 9
0
        public VendorEmailStatisticEntry(VendorStatisticsEntry entry)
        {
            this.Vendor = _context.Vendors.Where(x => x.Id == entry.VendorId).First();

            if (entry.CategoryId == 0)
            {
                this.CategoryName = "General List of ‘Suggested Service Providers‘";
            }
            else
            {
                this.CategoryName = _context.Categories.Where(x => x.Id == entry.CategoryId).First().Title;
            }

            this.OccurredAt = entry.OccurredAt;
            this.User       = _context.UserPurchases.Where(x => x.Id == entry.UserId).First();
        }
        public ActionResult EditUser(int?id)
        {
            if (id == null)
            {
                return(Redirect("../"));
            }

            try
            {
                UserPurchase userPurchase = _context.UserPurchases.First(x => x.Id == id);

                return(View(userPurchase));
            }
            catch (Exception e)
            {
                return(Redirect("../"));
            }
        }
Exemplo n.º 11
0
        private UserPurchase createUserPurchaseByPurchasedItem(PurchasedItem purchasedItem)
        {
            var salt = GenerateSequenceOfChars(20);
            // TODO: check facility name length
            var password = GeneratePassword(purchasedItem.Facility);

            var userPurchase = new UserPurchase();

            userPurchase.Email                = purchasedItem.Email;
            userPurchase.Name                 = purchasedItem.Name;
            userPurchase.PasswordSalt         = salt;
            userPurchase.Password             = HashPassword(password, salt);
            userPurchase.FacilityName         = purchasedItem.Facility;
            userPurchase.DateOfPurchase       = purchasedItem.DateOfPurchase;
            userPurchase.UserRegistrationDate = DateTime.Now;
            userPurchase.UserExpirationDate   = DateTime.Now.AddMonths(6);

            return(userPurchase);
        }
Exemplo n.º 12
0
        private DashboardItem createDasboardItemByUserPurchase(UserPurchase userPurchase)
        {
            var dashboardItem = new DashboardItem();

            dashboardItem.Email                = userPurchase.Email;
            dashboardItem.Name                 = userPurchase.Name;
            dashboardItem.Facility             = userPurchase.FacilityName;
            dashboardItem.DateOfPurchase       = userPurchase.DateOfPurchase;
            dashboardItem.UserRegistrationDate = userPurchase.UserRegistrationDate;
            dashboardItem.UserExpirationDate   = userPurchase.UserExpirationDate;

            if (dashboardItem.UserExpirationDate > DateTime.Now)
            {
                dashboardItem.status = PurchaseStatus.Active;
            }
            else
            {
                dashboardItem.status = PurchaseStatus.Expired;
            }

            return(dashboardItem);
        }
        public ActionResult ContactMe(int vendorId, int categoryId)
        {
            VendorStatisticsEntry entry = new VendorStatisticsEntry();

            entry.CategoryId = categoryId;
            entry.VendorId   = vendorId;
            entry.Type       = VendorStatisticsEntry.CONTACT_ME_TYPE;
            entry.OccurredAt = DateTime.Now;

            UserPurchase user = _userRepository.GetUserByEmail(User.Identity.Name,
                                                               (string)HttpContext.Session["facilityDateHash"]);

            entry.UserId = user.Id;

            _context.VendorStatisticsEntries.Add(entry);
            _context.SaveChanges();

            Vendor vendor = _context.Vendors.Find(vendorId);

            sendEmails(vendor, user, categoryId);

            return(Content("success"));
        }
        public ActionResult AddUser(UserPurchase userPurchase)
        {
            UserRepository userRepository = new UserRepository();

            if (ModelState.IsValid)
            {
                var salt = "ururu";

                userPurchase.Password     = UserRepository.HashPassword(userPurchase.Password.Trim(), salt);
                userPurchase.PasswordSalt = salt;
                userPurchase.Email        = userPurchase.Email.ToLower().Trim();
                if (userPurchase.ActivatorsEmail != null)
                {
                    userPurchase.ActivatorsEmail = userPurchase.ActivatorsEmail.ToLower().Trim();
                }

                userPurchase.DateOfPurchase       = DateTime.Now;
                userPurchase.UserRegistrationDate = DateTime.Now;

                //Check to make sure the combination of Email, Password, and Facilty is unique
                int existingUserCheck = _context.UserPurchases.Where(x => x.Email == userPurchase.Email && x.Password == userPurchase.Password && x.FacilityName == userPurchase.FacilityName).Count();

                if (existingUserCheck == 0)
                {
                    _context.UserPurchases.Add(userPurchase);
                    _context.SaveChanges();
                    return(RedirectToAction("Index"));
                }
                else
                {
                    ModelState.AddModelError("Email", "The combination of Email, Password, and Facility Name must be unique. ");
                }
            }

            return(View(userPurchase));
        }
        //
        // GET: /Admin/

        public ActionResult Index()
        {
            var hash   = (string)HttpContext.Session["facilityDateHash"];
            var userId = _userRepository.GetUserByEmail(User.Identity.Name, hash).Id;

            //Get User's Email address
            var userEmail = getUsersEmail();

            //Create ViewBag Attribute to hold Current User Details
            ViewBag.CurrentUser = _userRepository.GetUserById(userId);


            //Get User's information
            UserPurchase thisUser = _context.UserPurchases.First(x => x.Email == userEmail);

            //if user is not an admin, then logout user
            if (!thisUser.IsAdmin)
            {
                FormsAuthentication.SignOut();
                return(RedirectToAction("Index"));
            }

            return(View(new UsersList()));
        }
Exemplo n.º 16
0
        //
        // GET: /Home/
        public ActionResult Index()
        {
            //TODO: add try catch block - Mithgol, please unlogin
            QuestionnaireWithSelectedAnswers questionnaire;

            var hash   = (string)HttpContext.Session["facilityDateHash"];
            var userId = _userRepository.GetUserByEmail(User.Identity.Name, hash).Id;

            questionnaire = _questionnaireRepository.getQuestionnaireProbablyWithSelectedAnswers(userId);

            UserPurchase user = _userRepository.GetUserById(userId);

            QuestionnaireWithSelectedAnswersForUser questionnaireForUser =
                new QuestionnaireWithSelectedAnswersForUser(questionnaire, user);

            if (questionnaire != null)
            {
                return(View(questionnaireForUser));
            }
            else
            {
                return(Redirect("Error"));
            }
        }
Exemplo n.º 17
0
 public UserDetails(UserPurchase user, QuestionnaireReport questionnaireReport)
 {
     this.UserPurchase        = user;
     this.QuestionnaireReport = questionnaireReport;
 }
        public QuestionnaireWithSelectedAnswersForUser(QuestionnaireWithSelectedAnswers questionniare, UserPurchase user)
        {
            this.Questionnaire = questionniare;

            UserData              = new UserData();
            UserData.Email        = user.Email;
            UserData.Name         = user.Name;
            UserData.FacilityName = user.FacilityName;

            DemographicData = new DemographicDataContainer();
            DemographicData.SizeOfFacility                  = user.SizeOfFacility;
            DemographicData.IndustrialClassification        = user.IndustrialClassification;
            DemographicData.AdditionalProductClassification = user.AdditionalProductClassification;
            DemographicData.AnotherProductClassification    = user.AnotherProductClassification;

            SubmittedStatusForUser status = _context.SubmittedeStatusForUsers.SingleOrDefault(x => x.UserId == user.Id);

            WasEverSubmitted = (status != null);
            if (status != null)
            {
                lastSubmitted = status.SubmitedDate;
            }
        }
 public static MailContent createVendorAdminReport(Vendor vendor, UserPurchase user, int categoryId)
 {
     return(createVendorReportEmail(vendor, adminEmail, user, categoryId));
 }
 public QuestionnaireReportForUser(QuestionnaireReport report, UserPurchase user)
 {
     this.Report       = report;
     this.UserPurchase = user;
 }
        private static MailContent createVendorReportEmail(Vendor vendor, String recipient, UserPurchase user, int categoryId)
        {
            MailContent mailContent = new MailContent();

            mailContent.MailFrom      = vendorsContactEmail;
            mailContent.MailingAdress = recipient;
            QuestionnaireContext _context = new QuestionnaireContext();
            String sectionName            = (categoryId != 0) ? _context.Categories.Where(x => x.Id == categoryId).First().Title
                : "General List of ‘Suggested Service Providers’";

            mailContent.Subject  = "Referral from AFFI-FSMA Assessments – Request for Information";
            mailContent.HtmlText = "<table border=\"0\" cellpadding=\"1\" cellspacing=\"1\" style=\"width: 600px;\">"
                                   + "<tbody><tr><td>"
                                   + "<img alt=\"\" src=\"http://affi-fsma.seneca.com/Content/img/affi_logo.jpg\" style=\"width: 100px; height: 73px;\" /></td>"
                                   + "<td><div><span style=\"font-size:18px;\"><strong>Responses from the AFFI &ndash; FSMA Self Assessment</strong></span></div>"
                                   + "<div><span style=\"font-size:18px;\"><strong>Request for Information to &ldquo;Suggested Service Provider&rdquo;</strong></span></div>"
                                   + "</td></tr></tbody></table><br/>"
                                   + "<span style=\"font-size:16px;\">TO: " + vendor.Name + "<br/><br/>"
                                   + "The following person has clicked on the “Contact Me” button while taking the AFFI – FSMA Self-Assessment:<br/><br/>"
                                   + "Name of person: " + user.Name + "<br/>"
                                   + "Facility name: " + user.FacilityName + "<br/>"
                                   + "Email address: " + user.Email + "<br/>"
                                   + "Date and time: " + DateTime.Now.ToLongDateString() + " " + DateTime.Now.ToShortTimeString() + "<br/><br/>"
                                   + "Section of the AFFI – FSMA Self-Assessment Report: " + sectionName + "<br/><br/>"
                                   + "By clicking on the Contact Me button the person anticipates that they will receive information about your company’s services related to the section of the FSMA Self-Assessment Report as referenced above.<br/><br/>"
                                   + "If you have any questions about this email, please “Reply” to this email with your questions.<br/><br/>"
                                   + "Thank you – <br/>"
                                   + "Seneca Corporation</span>";
            return(mailContent);
        }
Exemplo n.º 22
0
        public ActionResult Activate(PurchasedItemModel model, string returnUrl)
        {
            if (!ModelState.IsValid)
            {
                return(Redirect("Index"));
            }

            string facilityName   = model.Facility;
            string userName       = model.Name;
            string email          = model.Email;
            string dateOfPurchase = model.DateOfPurchase;
            List <PurchasedItem> purchasedItems = GetStoredPurchasedItems();

            if (purchasedItems == null)
            {
                return(LogOutAndRedirectToLoginPage());
            }
            DateTime date = DateTime.Parse(dateOfPurchase);

            var purchasedItem = purchasedItems.Find(i => Math.Abs(i.DateOfPurchase.Subtract(date).TotalSeconds) < 1);

            if (purchasedItem != null)
            {
                var count = context.UserPurchases.Where(u => EntityFunctions.DiffSeconds(u.DateOfPurchase, purchasedItem.DateOfPurchase) < 1).Count();

                //if(count != 0)
                //    return Content("<html><head></head><body><h1>Error! This item already activated </h1></body></html>");


                var salt = GenerateSequenceOfChars(20);
                // TODO: check facility name length
                var password = GeneratePassword(facilityName);

                //TODO: move following code to method
                var userPurchase = new UserPurchase();

                userPurchase.Email                = email;
                userPurchase.ActivatorsEmail      = User.Identity.Name;
                userPurchase.Name                 = userName;
                userPurchase.PasswordSalt         = salt;
                userPurchase.Password             = HashPassword(password, salt);
                userPurchase.FacilityName         = facilityName;
                userPurchase.DateOfPurchase       = purchasedItem.DateOfPurchase;
                userPurchase.UserRegistrationDate = DateTime.Now;
                userPurchase.UserExpirationDate   = DateTime.Now.AddMonths(6);

                context.UserPurchases.Add(userPurchase);
                context.SaveChanges();

                HttpContext.Session["lastPurchase"]         = userPurchase;
                HttpContext.Session["lastPurchasePassword"] = password;

                //Send an email to user
                IMailService mailService = new SmptMailService(System.Configuration.ConfigurationManager.AppSettings["smtpServer"]);

                MailContent mailContent = new MailContent();
                mailContent.MailFrom      = "*****@*****.**";
                mailContent.MailingAdress = userPurchase.Email;
                mailContent.Subject       = "AFFI FSMA Self-Assessment Login Credentials and Instructions";

                mailContent.HtmlText = "<html><head></head><body>Dear " + userPurchase.Name + ":<br/>" +
                                       "<p>When you want to begin your FSMA Self-Assessment for your facility (<b>" + userPurchase.FacilityName + "</b>), you can just click on the Login link below.</p>" +
                                       "<p>Your login credentials for the FSMA Self-Assessment are: </p>" +
                                       "<p><b>Userid: </b>" + userPurchase.Email + "</p>" +
                                       "<p><b>Password: </b>" + password + "</p>" +
                                       "<p>If you have any questions regarding the FSMA Self-Assessment Tool, please contact AFFI Vice President of Regulatory and Technical Affairs Dr. Donna Garren at <a href=\"mailto:[email protected]\">[email protected]</a> or (703) 821-0770.</p>" +
                                       "<p>Thank you.</p>" +
                                       "<p><a href=\"http://affi-fsma.seneca.com/signIn\" target=\"_blank\">Click Here to Login</a></p></body></html>";

                mailContent.PlainText = mailContent.HtmlText;
                mailService.sendMail(mailContent);

                //And if needed - to a person who had activated the purchase (if not same person)
                if (userPurchase.Email != userPurchase.ActivatorsEmail)
                {
                    mailContent.MailingAdress = userPurchase.ActivatorsEmail;
                    mailService.sendMail(mailContent);
                }

                return(Redirect("Index"));
            }
            else
            {
                return(Content("<html><head></head><body><h1>Error!Can't find purchasedItem</h1></body></html>"));
            }
        }