Esempio n. 1
0
        public void CanCreateAccessoriesCombination()
        {
            IClosetRepository    cr      = new ClosetRepository();
            IOutfitEngineService service = CreateOutfitEngineService();

            IList <int> lst    = new List <int>();
            string      values = "244531,1309246,2062726,2979991,2981161,2980771,178231,178621,172771,169261,170041,2554111,2555281,3029131,3029911,3030691";

            foreach (string val in values.Split(','))
            {
                lst.Add(Convert.ToInt32(val));
            }

            cr.DbContext.BeginTransaction();
            Closet c = cr.Get(2);

            foreach (int i in lst)
            {
                c.AddGarment(new MasterGarment(i));
            }
            cr.SaveOrUpdate(c);
            cr.DbContext.CommitTransaction();

            IList <int> lstFlavors = new List <int>();

            lstFlavors.Add(1);

            service.AddOutfits(2, lst);
        }
Esempio n. 2
0
        public void CanCreateLargeClosetWithAccessoriesCombination()
        {
            IClosetRepository    cr      = new ClosetRepository();
            IOutfitEngineService service = CreateOutfitEngineService();

            IList <int> lst    = new List <int>();
            string      values = "781,14431,54601,55771,56551,62791,107251,109201,123631,179011,180571,391951,670411,671588,861908,948871,962911,1000748,1325611,1326001,1337191,1391131,1571311,1735111,1749931,1915305,1916851,1918411,2064271,2070901,2586871,2637961,2752621,2848951,2996371,2998321,3040051,3066181";

            foreach (string val in values.Split(','))
            {
                lst.Add(Convert.ToInt32(val));
            }

            cr.DbContext.BeginTransaction();
            Closet c = cr.Get(2);

            foreach (int i in lst)
            {
                c.AddGarment(new MasterGarment(i));
            }
            cr.SaveOrUpdate(c);
            cr.DbContext.CommitTransaction();

            IList <int> lstFlavors = new List <int>();

            lstFlavors.Add(1);
            lstFlavors.Add(8);

            service.AddOutfits(2, lst);
        }
Esempio n. 3
0
        public void CanCreateSummerCombinationWithCoats()
        {
            IClosetRepository    cr      = new ClosetRepository();
            IOutfitEngineService service = CreateOutfitEngineService();

            IList <int> lst    = new List <int>();
            string      values = "244531,245311,246091,1587706,1588876,1589656,2210146,2211316,2226526,2227696,2979991,2981161";

            foreach (string val in values.Split(','))
            {
                lst.Add(Convert.ToInt32(val));
            }

            cr.DbContext.BeginTransaction();
            Closet c = cr.Get(2);

            foreach (int i in lst)
            {
                c.AddGarment(new MasterGarment(i));
            }
            cr.SaveOrUpdate(c);
            cr.DbContext.CommitTransaction();

            IList <int> lstFlavors = new List <int>();

            lstFlavors.Add(1);
            lstFlavors.Add(6);

            service.AddOutfits(2, lst);
        }
Esempio n. 4
0
        private Closet CreateCloset()
        {
            IList <PreGarment> garments = CreatePreGarments();
            Closet             c        = new Closet();

            c.User = new PublicUser();
            IList <UserFlavor> flavors = new List <UserFlavor>();

            flavors.Add(new UserFlavor(CreateFashionFlavors()[0], 1));
            //flavors.Add(new UserFlavor(CreateFashionFlavors()[1], 1));
            //flavors.Add(new UserFlavor(CreateFashionFlavors()[2], 1));
            //flavors.Add(new UserFlavor(CreateFashionFlavors()[3], 1));
            //flavors.Add(new UserFlavor(CreateFashionFlavors()[4], 1));
            //flavors.Add(new UserFlavor(CreateFashionFlavors()[5], 1));
            c.User.SetFlavors(flavors);
            c.User.AddEventType(CreateEventTypes()[0]);
            //c.User.AddEventType(CreateEventTypes()[1]);
            //c.User.AddEventType(CreateEventTypes()[2]);
            //c.User.AddEventType(CreateEventTypes()[3]);
            //c.User.AddEventType(CreateEventTypes()[4]);
            //c.User.AddEventType(CreateEventTypes()[5]);

            foreach (PreGarment pg in garments)
            {
                c.AddGarment(CreateGarment(pg));
            }

            return(c);
        }
Esempio n. 5
0
        public ActionResult UploadFile(FormCollection values)
        {
            MembershipUser mu = Membership.GetUser();

            if (mu != null)
            {
                ViewData["UserName"] = mu.UserName;
            }

            ArrayList           lst      = GetFormatedValues(values);
            RegisteredUser      user     = registeredUserRepository.GetByMembershipId(Convert.ToInt32(mu.ProviderUserKey));
            IList <UserGarment> lstFiles = new List <UserGarment>();

            for (int i = 0; i < Request.Files.Count - 1; i++)
            {
                HttpPostedFileBase uploadedFile = Request.Files[i];
                if (uploadedFile.ContentLength != 0)
                {
                    UserGarment ug = (UserGarment)lst[i];
                    ug.User     = user;
                    ug.ImageUri = "";
                    ug.LinkUri  = "";
                    userGarmentRepository.SaveOrUpdate(ug);

                    FileInfo fi       = new FileInfo(uploadedFile.FileName);
                    string   fileName = ug.Id.ToString() + fi.Extension;
                    string   filePath = Path.Combine(Server.MapPath("/res/Garments/"), fileName);
                    uploadedFile.SaveAs(filePath);

                    Closet closet = user.Closet;
                    closet.AddGarment(ug);
                    closetRepository.SaveOrUpdate(closet);

                    ug.ImageUri = fileName;
                    userGarmentRepository.SaveOrUpdate(ug);
                    lstFiles.Add(ug);
                }
            }

            ViewData["uploadedFiles"] = lstFiles;
            return(View());
        }
Esempio n. 6
0
        public void CanCreateBigClosetCombination(string values, int flavor1, int flavor2)
        {
            IClosetRepository        cr  = new ClosetRepository();
            IFashionFlavorRepository fr  = new FashionFlavorRepository();
            IBasicUserRepository     bur = new BasicUserRepository();

            IOutfitEngineService service = CreateOutfitEngineService();

            IList <int> lst = new List <int>();

            foreach (string val in values.Split(','))
            {
                lst.Add(Convert.ToInt32(val));
            }

            cr.DbContext.BeginTransaction();
            Closet c = cr.Get(2);

            foreach (int i in lst)
            {
                c.AddGarment(new MasterGarment(i));
            }
            cr.SaveOrUpdate(c);

            IList <UserFlavor> lstFlavors = new List <UserFlavor>();

            lstFlavors.Add(new UserFlavor(fr.Get(flavor1), 1));
            if (flavor2 != 0)
            {
                lstFlavors.Add(new UserFlavor(fr.Get(flavor2), 1));
            }

            c.User.SetFlavors(lstFlavors);

            bur.SaveOrUpdate(c.User);
            cr.DbContext.CommitTransaction();

            service.CreateOutfits(2);

            c = cr.Get(2);
            Assert.IsTrue(c.Outfits.Count > 0);
        }
Esempio n. 7
0
        public JsonResult AddToCloset(WishListSelection wls)
        {
            closetRepository.DbContext.BeginTransaction();
            // Remove from Wish List
            Garment  g  = new MasterGarment(wls.GarmentId);
            WishList wl = wishListRepository.GetForUser(this.ProxyLoggedUser);

            wl.RemoveWishGarment(new WishGarment(wls.WishListId));

            // Add to closet
            Closet c = closetRepository.Get(this.ClosetId);

            c.AddGarment(g);
            closetRepository.DbContext.CommitTransaction();

            List <int> ids = new List <int>();

            ids.Add(wls.GarmentId);
            // Update the closet combinations
            (new FashionAde.Utils.OutfitEngineService.OutfitEngineServiceClient()).AddOutfits(this.ClosetId, ids);

            return(Json(new { Success = true }));
        }
Esempio n. 8
0
        public void CanCreateWithOtherAccessories()
        {
            IClosetRepository cr = new ClosetRepository();

            IList <int> lst    = new List <int>();
            string      values = "89701,94771,95161,99451,100231,162241,162631,163021,179011,181351,184471,184861,189541,244921,246091,249991,251161,256621,277291,278461,283921,287431,588511,594361,599431,703171,707851,709021,713701,998401,1003471,1007761,1008151,1342381,1343551,1347451,1351351,1353691,2177371,2181661,2182051,2182831,2186731,2210521,2215201,2216371,2717911,2727661,2729611,2731171,2979991,2981551,2985061,2986621,3029131,3029521,3033811,3039661";

            foreach (string val in values.Split(','))
            {
                lst.Add(Convert.ToInt32(val));
            }

            cr.DbContext.BeginTransaction();
            Closet c = cr.Get(2);

            foreach (int i in lst)
            {
                c.AddGarment(new MasterGarment(i));
            }
            cr.SaveOrUpdate(c);
            cr.DbContext.CommitTransaction();

            IList <int> lstFlavors = new List <int>();

            lstFlavors.Add(1);
            lstFlavors.Add(5);

            IOutfitEngineService service = CreateOutfitEngineService();

            service.AddOutfits(2, lst);

            //IList<int> lstFlavors = new List<int>();
            //lstFlavors.Add(1);

            //Assert.IsTrue(service.HasValidCombinations(lst, lstFlavors));
        }
Esempio n. 9
0
        public bool RegisterMember(string email, string userName, string firstName, string lastName, string password,
                                   UserSize userSize, int membershipUserId, string zipCode,
                                   IList <UserFlavor> userFlavors, IList <EventType> eventTypes,
                                   IList <Garment> mygarments, IList <Garment> mywishlist,
                                   string validateUri, string channel,
                                   string invitationCode)
        {
            bool mustConfirmMail = true;

            try
            {
                IDictionary <string, object> propertyValues;
                bool invited = false;

                email    = email.ToLower().Trim();
                userName = userName.ToLower().Trim();

                basicUserRepository.DbContext.BeginTransaction();

                if (!string.IsNullOrEmpty(invitationCode))
                {
                    propertyValues = new Dictionary <string, object>();
                    propertyValues.Add("Code", invitationCode);
                    InvitationCode ic = invitationCodeRepository.FindOne(propertyValues);

                    if (!invitationValidatorService.IsValidCode(ic))
                    {
                        throw new InvalidInvitationCodeException();
                    }

                    mustConfirmMail = string.IsNullOrEmpty(ic.EmailAddress);
                    ic.MarkUsed();
                    invitationCodeRepository.SaveOrUpdate(ic);
                }

                RegisteredUser user = new RegisteredUser();
                user.UserName         = userName;
                user.FirstName        = firstName;
                user.LastName         = lastName;
                user.EmailAddress     = email.ToLower().Trim();
                user.Size             = userSize;
                user.PhoneNumber      = string.Empty;
                user.MembershipUserId = membershipUserId;
                user.RegistrationCode = Guid.NewGuid().ToString();  // Used for email verification purposes.
                user.ChangeZipCode(zipCode);
                user.SetFlavors(userFlavors);
                user.Channel = channel;

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

                // Create Closet
                Closet closet = new Closet();
                closet.User         = user;
                closet.PrivacyLevel = PrivacyLevel.Private;
                closet.MarkAsProcessed();

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

                // Check if the user does not exist with that mail
                propertyValues = new Dictionary <string, object>();
                propertyValues.Add("EmailAddress", email);
                BasicUser bu = basicUserRepository.FindOne(propertyValues);

                // HACK: We need to change the mail of the invited user to be able to add the new registered user.
                if (bu != null && bu is InvitedUser)
                {
                    InvitedUser iu = bu as InvitedUser;
                    iu.EmailAddressReplaced = iu.EmailAddress;
                    iu.EmailAddress        += new Random().Next().ToString();

                    basicUserRepository.SaveOrUpdate(iu);
                    basicUserRepository.DbContext.CommitTransaction();

                    basicUserRepository.DbContext.BeginTransaction();
                    closetRepository.SaveOrUpdate(closet);
                    basicUserRepository.SaveOrUpdate(user);

                    propertyValues = new Dictionary <string, object>();
                    propertyValues.Add("User", bu);
                    IList <Friend> lst = friendRepository.FindAll(propertyValues);
                    if (lst.Count > 0)
                    {
                        foreach (Friend f in lst)
                        {
                            Friend newFriend = new Friend();
                            newFriend.BasicUser = user;
                            newFriend.User      = f.BasicUser;
                            newFriend.Status    = FriendStatus.Pending;
                            friendRepository.SaveOrUpdate(newFriend);
                        }
                    }

                    invited = true;
                }
                else
                {
                    closetRepository.SaveOrUpdate(closet);
                    basicUserRepository.SaveOrUpdate(user);
                }

                // Create wishlist even if no items been selected for further use.
                WishList wl = new WishList();
                wl.User = user;

                // Save Wish List
                if (mywishlist != null && mywishlist.Count > 0)
                {
                    foreach (Garment wishlist in mywishlist)
                    {
                        wl.AddGarment(wishlist);
                    }
                }
                wishListRepository.SaveOrUpdate(wl);

                // Send Email Confirmation Mail
                if (mustConfirmMail)
                {
                    SendValidationCode(user, validateUri);
                }

                // Commit Transaction
                basicUserRepository.DbContext.CommitTransaction();

                new FashionAde.Utils.OutfitEngineService.OutfitEngineServiceClient().CreateOutfits(closet.Id);

                if (invited)
                {
                    basicUserRepository.MigrateInvited(bu as InvitedUser, user);
                }
            }
            catch
            {
                try { basicUserRepository.DbContext.RollbackTransaction(); }
                catch { }

                throw;
            }

            return(mustConfirmMail);
        }
Esempio n. 10
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));
        }
Esempio n. 11
0
        public ActionResult UploadFile(FormCollection values)
        {
            ArrayList           lst      = GetFormatedValues(values);
            RegisteredUser      user     = this.ProxyLoggedUser;
            IList <UserGarment> lstFiles = new List <UserGarment>();

            List <int> garmentsIds = new List <int>();

            userGarmentRepository.DbContext.BeginTransaction();

            for (int i = 0; i < Request.Files.Count - 1; i++)
            {
                HttpPostedFileBase uploadedFile = Request.Files[i];
                if (uploadedFile.ContentLength != 0)
                {
                    UserGarment ug = (UserGarment)lst[i];
                    ug.User     = user;
                    ug.ImageUri = "";
                    ug.LinkUri  = "";

                    // Find pregarment
                    IDictionary <string, object> propertyValues = new Dictionary <string, object>();
                    propertyValues.Add("Silouhette", ug.Tags.Silouhette);
                    propertyValues.Add("PatternType", ug.Tags.Pattern.Type);
                    propertyValues.Add("ColorFamily", ug.Tags.DefaultColor.Family);
                    ug.PreGarment = pregarmentRepository.FindOne(propertyValues);
                    ug.UpdateSeasonCode();
                    ug.UpdateEventTypeCode();
                    userGarmentRepository.SaveOrUpdate(ug);

                    FileInfo fi       = new FileInfo(uploadedFile.FileName);
                    string   fileName = "user_" + ug.Id.ToString() + fi.Extension;

                    string path          = ConfigurationManager.AppSettings["Resources_Path"];
                    string filePath      = Path.Combine(Path.Combine(path, @"Garments\UploadedImages\"), fileName);
                    string smallImgPath  = Path.Combine(Path.Combine(path, @"Garments\65\"), fileName);
                    string largelImgPath = Path.Combine(Path.Combine(path, @"Garments\95\"), fileName);

                    uploadedFile.SaveAs(filePath);

                    // TODO: Improve borders.
                    ImageHelper.MakeTransparent(filePath);

                    ResizeImage(filePath, largelImgPath, 135, 95, true); //Imagenes Grandes
                    ResizeImage(filePath, smallImgPath, 65, 65, true);   //Imagenes Pequeñas

                    ug.ImageUri = fileName;
                    userGarmentRepository.SaveOrUpdate(ug);
                    lstFiles.Add(ug);

                    Closet closet = closetRepository.Get(this.ClosetId);
                    closet.AddGarment(ug);
                    closetRepository.SaveOrUpdate(closet);

                    garmentsIds.Add(ug.Id);
                }
            }

            userGarmentRepository.DbContext.CommitTransaction();

            new FashionAde.Utils.OutfitEngineService.OutfitEngineServiceClient().AddOutfits(user.Closet.Id, garmentsIds);

            ViewData["uploadedFiles"] = lstFiles;
            return(View());
        }