예제 #1
0
        public ViewResult AddFriends(FormCollection values)
        {
            List <int>     selectedIndexs  = new List <int>();
            List <Friend>  selectedFriends = new List <Friend>();
            MembershipUser mu   = Membership.GetUser();
            RegisteredUser user = registeredUserRepository.GetByMembershipId(Convert.ToInt32(mu.ProviderUserKey));

            foreach (var value in values)
            {
                object o = values[value.ToString()];
                if (o.ToString().Contains("true"))
                {
                    selectedIndexs.Add(Convert.ToInt32(value.ToString().Split('_')[1]));
                }
            }

            if (Session["GMailToken"] != null)
            {
                selectedFriends = GetGmailContacts(selectedIndexs);
            }

            user.AddFriends(selectedFriends);
            registeredUserRepository.SaveOrUpdate(user);

            return(View("FriendSelection", selectedFriends));
        }
        public ActionResult Validate(string userid, string code)
        {
            if (!string.IsNullOrEmpty(code) && !string.IsNullOrEmpty(userid))
            {
                int userId = Convert.ToInt32(userid);

                MembershipUser mu = Membership.GetUser(userId);
                if (mu != null)
                {
                    RegisteredUser ru = registeredUserRepository.GetByMembershipId(userId);

                    if (!mu.IsApproved)
                    {
                        // Make sure is using the valid code
                        if (ru != null && ru.RegistrationCode.Trim().ToLower() == code.Trim().ToLower())
                        {
                            // Approve on Membership
                            mu.IsApproved = true;
                            Membership.UpdateUser(mu);

                            // Approve on System
                            ru.Confirm();
                            ru.Closet.PrivacyLevel = PrivacyLevel.FullCloset;
                            registeredUserRepository.SaveOrUpdate(ru);
                            // Send approval mail
                            messageSenderService.SendWithTemplate("approvedmail", ru, ru.UserName, ru.EmailAddress);
                            return(RedirectToAction("Index", "Login", new { validatedUser = true }));
                        }
                    }
                    else
                    {
                        if (ru != null && ru.RegistrationCode.Trim().ToLower() == code.Trim().ToLower())
                        {
                            ru.EmailAddress = ru.NewMail;
                            mu.Email        = ru.EmailAddress;
                            ru.NewMail      = string.Empty;
                            registeredUserRepository.SaveOrUpdate(ru);
                            Membership.UpdateUser(mu);
                            // Send approval mail
                            messageSenderService.SendWithTemplate("approvedmail", ru, ru.UserName, ru.EmailAddress);
                            return(RedirectToAction("Index", "Home", new { validatedUser = true }));
                        }
                    }
                }
            }

            return(RedirectToAction("Index", new { invalidCode = true, userid = userid }));
        }
예제 #3
0
        /// <summary>
        /// Actualiza los UserFlavors del usuario por los nuevos seleccionados.
        /// </summary>
        /// <param name="Flavor1Weight">Peso del primer Fashion Flavor seleccionado.</param>
        /// <param name="Flavor2Weight">Peso del segudno Fashion Falvor determinado.</param>
        /// <param name="values">Coleccion de objetos del formulario</param>
        /// <returns>Actualiza los flavors seleccionados y redirecciona a la Home.</returns>
        public ActionResult UpdateUserFlavors(string Flavor1Weight, string Flavor2Weight, string submit)
        {
            bool previous = (submit != null && submit.ToLower() == "previous");

            if (previous)
            {
                return(RedirectToAction("Index", "FlavorSelect"));
            }

            IList <FashionFlavor> flavors     = ClosetState.Flavors;
            IList <UserFlavor>    userFlavors = new List <UserFlavor>();

            if (flavors != null)
            {
                if (!string.IsNullOrEmpty(Flavor1Weight))
                {
                    userFlavors.Add(new UserFlavor(flavors[0], Convert.ToDecimal(Flavor1Weight)));
                }
                if (!string.IsNullOrEmpty(Flavor2Weight))
                {
                    userFlavors.Add(new UserFlavor(flavors[1], Convert.ToDecimal(Flavor2Weight)));
                }
            }

            RegisteredUser user = registeredUserRepository.Get(this.UserId);

            List <int> flavorsIds    = new List <int>();
            List <int> myGarmentsIds = new List <int>();

            foreach (FashionFlavor ff in flavors)
            {
                flavorsIds.Add(ff.Id);
            }

            IList <ClosetGarment> closetGarments = closetRepository.GetGarmentsForUser(user);

            foreach (ClosetGarment closetGarment in closetGarments)
            {
                myGarmentsIds.Add(closetGarment.Garment.Id);
            }

            if (!new OutfitEngineServiceClient().HasValidCombinations(myGarmentsIds, flavorsIds))
            {
                return(RedirectToAction("FlavorChangeResult", "FlavorSelect", new { flavorsChanged = false }));
            }

            user.SetFlavors(userFlavors);

            //Update UserFlavors
            registeredUserRepository.DbContext.BeginTransaction();
            registeredUserRepository.SaveOrUpdate(user);
            registeredUserRepository.DbContext.CommitTransaction();

            new OutfitEngineServiceClient().CreateOutfits(user.Closet.Id);
            UserDataHelper.LoadFromDatabase();

            return(RedirectToAction("FlavorChangeResult", "FlavorSelect", new { flavorsChanged = true }));
        }
예제 #4
0
        public ActionResult DeleteFriends(string selectedIndexs, string selectedAll)
        {
            string[] selected = selectedIndexs.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

            bool       all    = selectedAll == "true";
            List <int> indexs = new List <int>();

            foreach (string index in selected)
            {
                indexs.Add(Convert.ToInt32(index));
            }

            RegisteredUser ru = registeredUserRepository.Get(UserId);

            if (!all)
            {
                foreach (int i in indexs)
                {
                    Friend friend = friendRepository.Get(i);
                    ru.RemoveFriend(friend);
                }
            }
            else
            {
                IList <Friend> tmp = friendRepository.Search(ru, string.Empty, FriendStatus.All, 0);
                foreach (Friend friend in tmp)
                {
                    if (indexs.Exists(delegate(int record) { if (record == friend.Id)
                                                             {
                                                                 return(true);
                                                             }
                                                             return(false); }))
                    {
                        ru.RemoveFriend(friend);
                    }
                }
            }

            registeredUserRepository.SaveOrUpdate(ru);

            return(RedirectToAction("Index"));
        }
예제 #5
0
        public ViewResult ChangeInfo(UserFull userModification)
        {
            if (ModelState.IsValid)
            {
                MembershipUser mu = Membership.GetUser();
                RegisteredUser ru = (RegisteredUser)registeredUserRepository.GetByMembershipId(Convert.ToInt32(mu.ProviderUserKey));
                userModification.Email = ru.EmailAddress;
                ru.FirstName           = userModification.FirstName;
                ru.LastName            = userModification.LastName;
                ru.PhoneNumber         = string.Empty;
                ru.ChangeZipCode(userModification.ZipCode);
                ru.Size = userSizeRepository.Get(userModification.UserSize);

                if (userModification.PrivacyStatus == PrivacyLevel.Private.ToString())
                {
                    ru.Closet.PrivacyLevel = PrivacyLevel.Private;
                }
                if (userModification.PrivacyStatus == PrivacyLevel.Friends.ToString())
                {
                    ru.Closet.PrivacyLevel = PrivacyLevel.Friends;
                }
                if (userModification.PrivacyStatus == PrivacyLevel.FavoriteOutfit.ToString())
                {
                    ru.Closet.PrivacyLevel = PrivacyLevel.FavoriteOutfit;
                }
                if (userModification.PrivacyStatus == PrivacyLevel.FullCloset.ToString())
                {
                    ru.Closet.PrivacyLevel = PrivacyLevel.FullCloset;
                }

                registeredUserRepository.SaveOrUpdate(ru);
                userModification.Alert = "User information updated successfully";
            }

            GetAccountData(userModification);
            return(View("Index", userModification));
        }
예제 #6
0
        public RedirectToRouteResult GoToMyGarments(string myGarmentsItems, string myWishListItems)
        {
            string[] myGarmentsArray = myGarmentsItems.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
            string[] myWishListArray = myWishListItems.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

            IList <Garment> myGarments        = new List <Garment>();
            List <int>      myGarmentsIds     = new List <int>();
            IList <Garment> myWishGarments    = new List <Garment>();
            List <int>      myWishGarmentsIds = new List <int>();

            if (myGarmentsArray.Length > 0)
            {
                foreach (string garment in myGarmentsArray)
                {
                    if (!string.IsNullOrEmpty(garment) && StringHelper.IsNumber(garment))
                    {
                        myGarmentsIds.Add(Convert.ToInt32(garment));
                    }
                }
            }
            if (myWishListArray.Length > 0)
            {
                foreach (string garment in myWishListArray)
                {
                    if (!string.IsNullOrEmpty(garment) && StringHelper.IsNumber(garment))
                    {
                        myWishGarmentsIds.Add(Convert.ToInt32(garment));
                    }
                }
            }

            garmentRepository.DbContext.BeginTransaction();
            myGarments     = garmentRepository.GetByIds(myGarmentsIds);
            myWishGarments = garmentRepository.GetByIds(myWishGarmentsIds);
            List <int>     newGarmentsIds = new List <int>();
            RegisteredUser user           = registeredUserRepository.Get(this.UserId);

            if (myGarments.Count > 0)
            {
                foreach (Garment garment in myGarments)
                {
                    if (!user.Closet.HasGarment(garment))
                    {
                        user.Closet.AddGarment(garment);
                        newGarmentsIds.Add(garment.Id);
                    }
                }
                registeredUserRepository.SaveOrUpdate(user);
            }

            if (myWishGarments.Count > 0)
            {
                WishList wl = wishListRepository.GetForUser(this.ProxyLoggedUser);
                if (wl == null)
                {
                    wl      = new WishList();
                    wl.User = this.ProxyLoggedUser;
                }
                foreach (Garment garment in myWishGarments)
                {
                    wl.AddGarment(garment);
                }
                wishListRepository.SaveOrUpdate(wl);
            }

            garmentRepository.DbContext.CommitTransaction();

            if (newGarmentsIds.Count > 0)
            {
                // Update the closet combinations
                new FashionAde.Utils.OutfitEngineService.OutfitEngineServiceClient().AddOutfits(user.Closet.Id, newGarmentsIds);
            }

            return(RedirectToAction("Index", "MyGarments"));
        }
예제 #7
0
        public ViewResult Register(UserRegistration userRegistration)
        {
            var errors = userRegistration.Validate();

            if (errors == null)
            {
                IList <UserFlavor> userFlavors = Session["UserFlavorSelected"] as List <UserFlavor>;
                IList <EventType>  eventTypes  = Session["EventTypeSelected"] as List <EventType>;
                IList <Garment>    mygarments  = Session["MyGarments"] as List <Garment>;
                IList <Garment>    mywishlist  = Session["MyWishList"] as List <Garment>;

                PublicUser user = new PublicUser();
                user.EmailAddress = userRegistration.Email;
                user.ChangeZipCode(userRegistration.ZipCode);
                user.SetFlavors(userFlavors);
                user.Size = new UserSize(Convert.ToInt32(userRegistration.UserSize));

                //TODO: Get the UserId from ASP.NET Membership
                MembershipCreateStatus status;
                MembershipUser         mu = Membership.CreateUser(userRegistration.UserName, userRegistration.Password, userRegistration.Email, securityQuestionRepository.Get(Convert.ToInt32(userRegistration.SecurityQuestion)).Description, userRegistration.SecurityAnswer, true, out status);
                if (status != MembershipCreateStatus.Success)
                {
                    errors = new ErrorSummary();
                    errors.RegisterErrorMessage("MembershipUser", status.ToString());
                    return(RegistrationError(userRegistration, errors.ErrorMessages));
                }
                user.MembershipUserId = Convert.ToInt32(mu.ProviderUserKey);
                user.FirstName        = string.Empty;
                user.LastName         = string.Empty;
                user.PhoneNumber      = string.Empty;

                if (eventTypes != null)
                {
                    foreach (EventType eventType in eventTypes)
                    {
                        user.AddEventType(eventType);
                    }
                }

                registeredUserRepository.SaveOrUpdate(user);
                Closet closet = new Closet();
                closet.User         = user;
                closet.PrivacyLevel = PrivacyLevel.Private;

                closetRepository.SaveOrUpdate(closet);
                if (mygarments != null)
                {
                    foreach (Garment garment in mygarments)
                    {
                        closet.AddGarment(garment);
                    }
                    closetRepository.SaveOrUpdate(closet);
                }
                user.Closet = closet;

                registeredUserRepository.SaveOrUpdate(user);

                if (mywishlist != null && mywishlist.Count > 0)
                {
                    WishList wl = new WishList();
                    wl.User = user;
                    foreach (Garment wishlist in mywishlist)
                    {
                        wl.AddGarment(wishlist);
                    }
                    wishListRepository.SaveOrUpdate(wl);
                }
                closetRepository.GenerateCloset(user);

                Session.Abandon();
                Session["UserRegistration"] = mu;
                return(View("RegistrationFinish", userRegistration));
            }

            return(RegistrationError(userRegistration, errors.ErrorMessages));
        }
예제 #8
0
        public ActionResult Register(UserRegistration userRegistration)
        {
            if (ModelState.IsValid)
            {
                IList <UserFlavor> userFlavors    = ClosetState.UserFlavors as List <UserFlavor>;
                IList <EventType>  eventTypes     = ClosetState.EventTypes as List <EventType>;
                IList <Garment>    mygarments     = garmentRepository.GetByIds(ClosetState.AddGarments) as List <Garment>;
                IList <Garment>    mywishlist     = garmentRepository.GetByIds(ClosetState.WishGarments) as List <Garment>;
                string             channel        = ClosetState.Channel;
                string             invitationCode = ClosetState.InvitationCode;

                SecurityQuestion sq = securityQuestionRepository.Get(Convert.ToInt32(userRegistration.SecurityQuestion));

                // Create Membership User
                MembershipCreateStatus status;
                MembershipUser         mu = Membership.CreateUser(userRegistration.UserName, userRegistration.Password, userRegistration.Email, sq.Description, userRegistration.SecurityAnswer, false, out status);
                if (status != MembershipCreateStatus.Success)
                {
                    ViewData["Errors"] = new string[] { status.ToString() }
                }
                ;

                try
                {
                    bool mustConfirmMail = registerMemberService.RegisterMember(userRegistration.Email,
                                                                                userRegistration.UserName, userRegistration.FirstName, userRegistration.LastName,
                                                                                userRegistration.Password,
                                                                                new UserSize(Convert.ToInt32(userRegistration.UserSize)),
                                                                                Convert.ToInt32(mu.ProviderUserKey),
                                                                                userRegistration.ZipCode,
                                                                                userFlavors,
                                                                                eventTypes,
                                                                                mygarments,
                                                                                mywishlist,
                                                                                Url.Action("Validate", "EmailConfirmation"),
                                                                                channel,
                                                                                invitationCode);

                    // Assign User Role
                    Roles.AddUserToRole(mu.UserName, "User");

                    if (mustConfirmMail)
                    {
                        ClosetState.Clear();
                        return(RedirectToAction("Index", "EmailConfirmation", new { userid = mu.ProviderUserKey }));
                    }

                    //The user already confirmed his email, so we need to approve him and go to the login
                    // Approve on Membership
                    mu.IsApproved = true;
                    Membership.UpdateUser(mu);

                    RegisteredUser ru =
                        registeredUserRepository.GetByMembershipId(Convert.ToInt32(mu.ProviderUserKey));

                    // Approve on System
                    ru.Confirm();
                    ru.Closet.PrivacyLevel = PrivacyLevel.FullCloset;
                    registeredUserRepository.SaveOrUpdate(ru);

                    ClosetState.Clear();
                    return(RedirectToAction("Index", "Login", new { validatedUser = true }));
                }
                catch (Exception ex)
                {
                    // Try to delete the incomplete created user because something went wrong.
                    try { Membership.DeleteUser(userRegistration.UserName); }
                    catch { }

                    if (ex is InvalidInvitationCodeException)
                    {
                        ModelState.AddModelError("InvitationCode", "The code is not valid or already used.");
                    }
                    else
                    {
                        throw;
                    }
                }
            }
            else
            {
                if (new List <ModelState>(ModelState.Values).Find(e => e.Value == null).Errors[0].ErrorMessage.StartsWith("Email"))
                {
                    ModelState.AddModelError("Email", "Email does not match.");
                }
                else
                {
                    ModelState.AddModelError("Password", "Password does not match.");
                }
            }

            GetRegistrationInfo(userRegistration);
            return(View("Index", userRegistration));
        }