public ActionResult Register()
        {
            var roles = GetAllRoles();
            var model = new RegisterViewModel();

            model.Roles = GenUtil.GetSelectListItems(roles);
            return(View(model));
        }
Exemplo n.º 2
0
        public ActionResult EditAddress(AddressViewModel model, string returnUrl)
        {
            SessionManager.RegisterSessionActivity();

            IEnumerable <string> regionAliases = GetAllRegionAliases();

            model.RegionAliases = GenUtil.GetSelectListItems(regionAliases);

            if (ModelState.IsValid)
            {
                DataProvider dataProvider = new DataProvider();

                DAL.Address address = dataProvider.FindAddressById(
                    int.Parse(DataSecurityTripleDES.GetPlainText(model.Id)));

                if (address != null)
                {
                    AddressDTO addressDTO = new AddressDTO()
                    {
                        Id          = model.Id,
                        City        = model.City,
                        Line1       = model.Line1,
                        Line2       = model.Line2,
                        Postcode    = model.Postcode,
                        RegionAlias = model.RegionAlias
                    };

                    using (DAL.CraveatsDbContext c = new DAL.CraveatsDbContext())
                    {
                        addressDTO.RegionId = DataSecurityTripleDES.GetEncryptedText(
                            c.Region.FirstOrDefault(r => r.CountryISO2 == "CA" &&
                                                    r.RegionAlias == addressDTO.RegionAlias).Id);

                        addressDTO.CountryId = DataSecurityTripleDES.GetEncryptedText(
                            c.Country.FirstOrDefault(s => s.ISO2 == "CA").Id);

                        address = c.Address.FirstOrDefault(u => u.Id == address.Id);
                        address = EntityDTOHelper.MapToEntity <AddressDTO, DAL.Address>(addressDTO, address);

                        c.SaveChanges();

                        return(RedirectToAction("ProfileView"));
                    }
                }
            }

            // Something is not right - so render the registration page again,
            // keeping the data user has entered by supplying the model.
            return(View("EditAddress", model));
        }
Exemplo n.º 3
0
        public ActionResult AddAddress(string ownerType = null, string ownerId = null)
        {
            if ((ownerType ?? string.Empty).Length > 0 && (ownerId ?? string.Empty).Length > 0)
            {
                ViewBag.AlterButtonTitle  = true;
                ViewBag.AlteredButtonName = "Next";
            }

            SessionManager.RegisterSessionActivity();

            if (Session != null && Session.Contents != null)
            {
                AuthenticatedUserInfo authenticatedUserInfo = Session["loggeduser"] as AuthenticatedUserInfo;

                if (authenticatedUserInfo != null)
                {
                    UserDTO userDTO = EntityDTOHelper.GetEntityDTO <DAL.User, UserDTO>(new CEUserManager().FindById(
                                                                                           int.Parse(DataSecurityTripleDES.GetPlainText(authenticatedUserInfo.UserId))));

                    if (((Common.UserTypeEnum)userDTO.UserTypeFlag).HasFlag(Common.UserTypeEnum.CraveatsDiner) ||
                        ((Common.UserTypeEnum)userDTO.UserTypeFlag).HasFlag(Common.UserTypeEnum.PartnerRestaurant))
                    {
                        IEnumerable <string> regionAliases = GetAllRegionAliases();

                        AddressViewModel addressViewModel = new AddressViewModel()
                        {
                            RegionAliases = GenUtil.GetSelectListItems(regionAliases),
                            OwnerId       = ownerId,
                            OwnerType     = ownerType
                        };

                        return(View("AddAddress", addressViewModel));
                    }
                }
            }
            return(View("Error"));
        }
        public ActionResult Register(RegisterViewModel model)
        {
            SessionManager.RegisterSessionActivity();

            // Get all states again
            var roles = GetAllRoles();

            // Set these states on the model. We need to do this because
            // only the selected value from the DropDownList is posted back, not the whole
            // list of states.
            model.Roles = GenUtil.GetSelectListItems(roles);

            // In case everything is fine - i.e. both "Name" and "State" are entered/selected,
            // redirect user to the "Done" page, and pass the user object along via Session
            if (ModelState.IsValid)
            {
                SHA1HashProvider sHA1HashProvider = new SHA1HashProvider();
                if (!ceUserManager.IsRegistered(model.Email))
                {
                    string sha1HashText = sHA1HashProvider.SecureSHA1(model.Password.Trim());
                    int?   newUserID    = ceUserManager.RegisterNew(model.Email, sha1HashText, model.Role);
                    if (newUserID.HasValue)
                    {
                        UserDTO userDTO = new UserDTO()
                        {
                            Id         = DataSecurityTripleDES.GetEncryptedText(newUserID),
                            FirstName  = model.FirstName,
                            Surname    = model.Surname,
                            UserStatus = (int?)UserStatusEnum.Active
                        };

                        ceUserManager.SaveUserDetail(userDTO);

                        StringBuilder sbSubject   = new StringBuilder("Craveats new registrant notification"),
                                      sbEmailBody = new StringBuilder("<p>A new user with the following detail has been registered in the system. " +
                                                                      $"<br/><em>FirstName            </em>: {model.FirstName}" +
                                                                      $"<br/><em>Surname              </em>: {model.Surname}" +
                                                                      $"<br/><em>Email                </em>: {model.Email}" +
                                                                      $"<br/><em>Registration Type    </em>: {model.Role}" +
                                                                      "</p><p>Thank you.</p><p>Craveats</p>");

                        CommunicationServiceProvider.SendOutgoingNotification(
                            new MailAddress(
                                model.Email,
                                string.Format("{0}{1}{2}", model.FirstName, " ", model?.Surname).Trim()),
                            sbSubject.ToString(),
                            sbEmailBody.ToString());

                        User result = ceUserManager.FindByCriteria(email: model.Email, userStatusEnums: new List <int> {
                            (int)UserStatusEnum.Active, (int)UserStatusEnum.Blocked
                        });
                        if (result != null)
                        {
                            userDTO = EntityDTOHelper.GetEntityDTO <User, UserDTO>(result);

                            AuthenticatedUserInfo authenticatedUserInfo = new AuthenticatedUserInfo(userDTO);
                            Session["loggeduser"] = authenticatedUserInfo;

                            SessionManager.RegisterSessionActivity(userID: result.Id, loggedInAt: DateTime.Now);

                            ceUserManager.SignInUser(HttpContext, string.Format("{0}", authenticatedUserInfo.FullName), false);

                            return(RedirectToAction("Index", "Home"));
                        }
                        else
                        {
                            ModelState.AddModelError(string.Empty, "An error occurred in reading user data. Please review input and re-try.");
                        }
                    }
                    else
                    {
                        ModelState.AddModelError(string.Empty, "An error occurred in registering new user. Please review input and re-try.");
                    }
                }
                else
                {
                    ModelState.AddModelError(string.Empty, "Email is registered and cannot be used to create another account.");
                }
            }

            // Something is not right - so render the registration page again,
            // keeping the data user has entered by supplying the model.
            return(View("Register", model));
        }
Exemplo n.º 5
0
        public ActionResult AddAddress(AddressViewModel model, string returnUrl)
        {
            SessionManager.RegisterSessionActivity();

            IEnumerable <string> regionAliases = GetAllRegionAliases();

            model.RegionAliases = GenUtil.GetSelectListItems(regionAliases);

            if (ModelState.IsValid)
            {
                AuthenticatedUserInfo authenticatedUserInfo = Session["loggeduser"] as AuthenticatedUserInfo;
                if (authenticatedUserInfo != null)
                {
                    int ownerType = model.OwnerType?.Length > 0
                        ? int.Parse(DataSecurityTripleDES.GetPlainText(model.OwnerType))
                        : -1;

                    int ownerId = model.OwnerId?.Length > 0
                        ? int.Parse(DataSecurityTripleDES.GetPlainText(model.OwnerType))
                        : -1;

                    DAL.User addressOwner = null;
                    if (!(ownerType > -1 && ownerId > 0))
                    {
                        addressOwner = new CEUserManager().FindById(
                            int.Parse(DataSecurityTripleDES.GetPlainText(authenticatedUserInfo.UserId)));
                    }

                    DataProvider dataProvider = new DataProvider();
                    AddressDTO   addressDTO   = new AddressDTO()
                    {
                        City        = model.City,
                        Line1       = model.Line1,
                        Line2       = model.Line2,
                        Postcode    = model.Postcode,
                        RegionAlias = model.RegionAlias
                    };

                    if (addressOwner != null && !addressOwner.AddressId.HasValue)
                    {
                        addressDTO.OwnerType = (int)Common.OwnerTypeEnum.User;
                        addressDTO.OwnerId   = authenticatedUserInfo.UserId;

                        using (DAL.CraveatsDbContext c = new DAL.CraveatsDbContext())
                        {
                            addressDTO.RegionId = DataSecurityTripleDES.GetEncryptedText(
                                c.Region.FirstOrDefault(r => r.CountryISO2 == "CA" &&
                                                        r.RegionAlias == addressDTO.RegionAlias).Id);

                            addressDTO.CountryId = DataSecurityTripleDES.GetEncryptedText(
                                c.Country.FirstOrDefault(s => s.ISO2 == "CA").Id);

                            DAL.Address newAddress = EntityDTOHelper.MapToEntity <AddressDTO, DAL.Address>(
                                addressDTO, null, true);
                            newAddress.AddressStatus = (int?)Common.AddressStatusEnum.Active;

                            c.Entry(newAddress).State = System.Data.Entity.EntityState.Added;

                            c.SaveChanges();

                            addressOwner = c.User.FirstOrDefault(u => u.Id == newAddress.OwnerId.Value);

                            addressOwner.AddressId   = newAddress.Id;
                            addressOwner.LastUpdated = DateTime.Now;

                            c.SaveChanges();

                            return(RedirectToAction("ProfileView", "Profile"));
                        }
                    }
                    else if (ownerType > -1 && ownerId > 0)
                    {
                        addressDTO.OwnerType = ownerType;
                        addressDTO.OwnerId   = model.OwnerId;

                        using (DAL.CraveatsDbContext c = new DAL.CraveatsDbContext())
                        {
                            addressDTO.RegionId = DataSecurityTripleDES.GetEncryptedText(
                                c.Region.FirstOrDefault(r => r.CountryISO2 == "CA" &&
                                                        r.RegionAlias == addressDTO.RegionAlias).Id);

                            addressDTO.CountryId = DataSecurityTripleDES.GetEncryptedText(
                                c.Country.FirstOrDefault(s => s.ISO2 == "CA").Id);

                            DAL.Address newAddress = EntityDTOHelper.MapToEntity <AddressDTO, DAL.Address>(
                                addressDTO, null, true);
                            newAddress.AddressStatus = (int?)Common.AddressStatusEnum.Active;

                            c.Entry(newAddress).State = System.Data.Entity.EntityState.Added;

                            c.SaveChanges();

                            DAL.Restaurant restaurant = c.Restaurant.FirstOrDefault(u => u.Id == newAddress.OwnerId.Value);

                            restaurant.AddressId   = newAddress.Id;
                            restaurant.LastUpdated = DateTime.Now;

                            c.SaveChanges();

                            return(RedirectToAction("Index", "RestaurantMenu", new
                            {
                                ownerType = DataSecurityTripleDES.GetEncryptedText((int)Common.OwnerTypeEnum.ServiceProvider),
                                ownerId = DataSecurityTripleDES.GetEncryptedText(restaurant.Id)
                            }));
                        }
                    }
                    ModelState.AddModelError("", "An address exists for this owner.");
                }
            }

            // Something is not right - so render the registration page again,
            // keeping the data user has entered by supplying the model.
            return(View(model));
        }
Exemplo n.º 6
0
        public ActionResult EditAddress(string id)
        {
            SessionManager.RegisterSessionActivity();

            if (Session != null && Session.Contents != null)
            {
                AuthenticatedUserInfo authenticatedUserInfo = Session["loggeduser"] as AuthenticatedUserInfo;

                if (authenticatedUserInfo != null)
                {
                    UserDTO userDTO = EntityDTOHelper.GetEntityDTO <DAL.User, UserDTO>(new CEUserManager().FindById(
                                                                                           int.Parse(DataSecurityTripleDES.GetPlainText(authenticatedUserInfo.UserId))));

                    if (((Common.UserTypeEnum)userDTO.UserTypeFlag).HasFlag(Common.UserTypeEnum.CraveatsDiner) ||
                        ((Common.UserTypeEnum)userDTO.UserTypeFlag).HasFlag(Common.UserTypeEnum.PartnerRestaurant))
                    {
                        DataProvider dataProvider = new DataProvider();
                        AddressDTO   addressDTO   = EntityDTOHelper.GetEntityDTO <DAL.Address, AddressDTO>(
                            dataProvider.FindAddressById(int.Parse(DataSecurityTripleDES.GetPlainText(id))));

                        if (addressDTO != null)
                        {
                            RegionDTO regionDTO = addressDTO.RegionId?.Trim().Length <= 0
                                ? null
                                : EntityDTOHelper.GetEntityDTO <DAL.Region, RegionDTO>(
                                dataProvider.FindRegionById(
                                    int.Parse(DataSecurityTripleDES.GetPlainText(addressDTO.RegionId))));

                            if (regionDTO != null)
                            {
                                addressDTO.RegionAlias = regionDTO.RegionAlias;
                                addressDTO.RegionName  = regionDTO.RegionName;
                            }

                            CountryDTO countryDTO = addressDTO.CountryId?.Trim().Length <= 0
                                ? null
                                : EntityDTOHelper.GetEntityDTO <DAL.Country, CountryDTO>(
                                dataProvider.FindCountryById(
                                    int.Parse(DataSecurityTripleDES.GetPlainText(addressDTO.CountryId))));

                            if (countryDTO != null)
                            {
                                addressDTO.CountryName = countryDTO.Name;
                            }
                        }

                        IEnumerable <string> regionAliases = GetAllRegionAliases();

                        AddressViewModel addressViewModel = new AddressViewModel()
                        {
                            Id            = addressDTO.Id,
                            City          = addressDTO.City,
                            Line1         = addressDTO.Line1,
                            Line2         = addressDTO.Line2,
                            Postcode      = addressDTO.Postcode,
                            RegionAlias   = addressDTO.RegionAlias,
                            RegionAliases = GenUtil.GetSelectListItems(regionAliases)
                        };

                        return(View("EditAddress", addressViewModel));
                    }
                }
            }
            return(View("Error"));
        }