Exemple #1
0
        public virtual void SetVisibility(ClosetOutfitVisibility visibility)
        {
            if (visibility == ClosetOutfitVisibility.Public)
            {
                bool isPublic = true;
                foreach (Garment g in this.Components)
                {
                    if (g is UserGarment)
                    {
                        UserGarment ug = (g as UserGarment);
                        if (!(ug.ApprovalStatus == ApprovalStatus.Approved && ug.Visibility == GarmentVisibility.Public))
                        {
                            isPublic = false;
                        }
                    }
                }

                if (!isPublic)
                {
                    this.visibility = ClosetOutfitVisibility.Private;
                }
            }

            this.visibility = visibility;
        }
Exemple #2
0
        /// <summary>
        /// Creates a new closet outfit in the system related with the current user.
        /// </summary>
        /// <param name="userId">User</param>
        /// <param name="garments">List of Garments</param>
        /// <param name="season">Season</param>
        /// <param name="visibility">Visibility</param>
        /// <exception cref="NotValidCombinationException">When a combination is not valid.</exception>
        public void CreateUserOutfit(int userId, IList <Garment> garments, Season season, ClosetOutfitVisibility visibility)
        {
            if (!OutfitValidationService.IsValidCombination(garments))
            {
                throw new NotValidCombinationException();
            }

            ClosetOutfit uo = new ClosetOutfit();

            // HACK: We need the garments saved with 0 in the non filled fields to make sure we have no duplicates.
            Garment hack = garmentRepository.Get(0);

            foreach (Garment g in garments)
            {
                uo.AddComponent(g, hack);
            }

            uo.Rating.CalculateEditorRating(uo.Components);

            BasicUser     bu = basicUserRepository.Get(userId);
            FashionFlavor ff = bu.GetPreferredFlavor();

            uo.FashionFlavor = ff;
            uo.Closet        = (bu as RegisteredUser).Closet;

            uo.SetSeason(season);
            uo.SetEventTypes(bu as RegisteredUser);
            uo.SetVisibility(visibility);

            //Agregar PreCombination
            PreCombination pc = preCombinationRepository.GetByGarments(uo.RetrieveCombinableComponents().ToList <Garment>(), ff);

            if (pc == null)
            {
                pc = new PreCombination();
                pc.FashionFlavor = ff;

                for (int j = 0; j < garments.Count; j++)
                {
                    Garment g = garments[j];
                    if (!OutfitValidationService.IsAccessory(g))
                    {
                        pc.AddPreGarment(garments[j]);
                    }
                }
            }

            uo.PreCombination = pc;
            uo.User           = bu as RegisteredUser;

            if (!uo.IsValid())
            {
                throw new NotValidCombinationException();
            }

            closetOutfitRepository.DbContext.BeginTransaction();

            // REVIEW: This may lead to orphaned records, given we cannot change the autonumeric for now because of the combination process.
            // TODO: Is better to check first if the Closet Outfit combination already exists and then proceed.
            preCombinationRepository.SaveOrUpdate(pc);

            try
            {
                closetOutfitRepository.SaveOrUpdate(uo);
                closetOutfitRepository.DbContext.BeginTransaction();
            }
            catch
            {
                closetOutfitRepository.DbContext.RollbackTransaction();
                throw new CombinationAlreadyExistsException();
            }
        }