コード例 #1
0
        public ListBlock <FavoriteDetails> GetFavoritesForUser(long userId, int startIndex, int count)
        {
            if (!UserProfileDao.Exists(userId))
            {
                throw new InstanceNotFoundException <UserProfileDetails>("userId", userId);
            }

            ListBlock <Favorite> favorites;

            try
            {
                favorites = FavoriteDao.ListForUser(userId, startIndex, count);
            }
            catch (InstanceNotFoundException <Favorite> )
            {
                return(new ListBlock <FavoriteDetails>(startIndex, false));
            }
            catch (NoMoreItemsException <Favorite> )
            {
                return(new ListBlock <FavoriteDetails>(startIndex, false));
            }

            List <FavoriteDetails> details = new List <FavoriteDetails>();

            foreach (Favorite favorite in favorites)
            {
                details.Add(new FavoriteDetails(favorite.favoriteId, favorite.linkId, favorite.name, favorite.description, favorite.date));
            }

            return(new ListBlock <FavoriteDetails>(details, favorites.Index, favorites.HasMore));
        }
コード例 #2
0
        public long AddToFavorites(long userId, long linkId, string name, string description)
        {
            if (!UserProfileDao.Exists(userId))
            {
                throw new InstanceNotFoundException <UserProfileDetails>("userId", userId);
            }
            if (!LinkDao.Exists(linkId))
            {
                throw new InstanceNotFoundException <LinkDetails>("linkId", linkId);
            }

            if (FavoriteDao.ExistsForUserAndLink(userId, linkId))
            {
                throw new DuplicateInstanceException <FavoriteDetails>("userId", userId, "linkId", linkId);
            }

            Favorite favorite = Favorite.CreateFavorite(-1, userId, linkId, name, description, DateTime.Now);

            try
            {
                FavoriteDao.Create(favorite);
            }
            catch (DuplicateInstanceException <Favorite> ex)
            {
                throw new InternalErrorException(ex);
            }

            return(favorite.favoriteId);
        }
コード例 #3
0
        public FavoriteDetails GetFavorite(long userId, long linkId)
        {
            if (!UserProfileDao.Exists(userId))
            {
                throw new InstanceNotFoundException <UserProfileDetails>("userId", userId);
            }

            if (!LinkDao.Exists(linkId))
            {
                throw new InstanceNotFoundException <LinkDetails>("linkId", linkId);
            }

            Favorite favorite;

            try
            {
                favorite = FavoriteDao.FindForUserAndLink(userId, linkId);
            }
            catch (InstanceNotFoundException <Favorite> ex)
            {
                throw new InstanceNotFoundException <FavoriteDetails>(ex.Properties);
            }
            catch (DuplicateInstanceException <Favorite> ex)
            {
                throw new InternalErrorException(ex);
            }

            return(new FavoriteDetails(favorite.favoriteId, favorite.linkId, favorite.name, favorite.description, favorite.date));
        }
コード例 #4
0
        public void ChangeDefaultCard(long userProfileId, long cardID)
        {
            UserProfile userProfile = null;
            Card        card        = null;

            try
            {
                userProfile = UserProfileDao.Find(userProfileId);
            } catch (InstanceNotFoundException e)
            {
                throw new InstanceNotFoundException(userProfileId, "User not found");
            }

            List <Card> userCards = userProfile.Cards.ToList <Card>();

            for (int i = 0; i < userCards.Count; i++)
            {
                if (userCards.ElementAt(i).defaultCard == true)
                {
                    userCards.ElementAt(i).defaultCard = false;
                    CardDao.Update(userCards.ElementAt(i));
                }
            }
            try
            {
                card = CardDao.Find(cardID);
            } catch (InstanceNotFoundException e)
            {
                throw new InstanceNotFoundException(cardID, "Trajeta no encontrada");
            }
            card.defaultCard = true;
            CardDao.Update(card);
        }
コード例 #5
0
ファイル: UserService.cs プロジェクト: lob94/Mad
        public ICollection <Recommendation> AddRecommendation(long eventId, ICollection <long> groups, long userId, string description)
        {
            Event e = EventDao.Find(eventId);
            ICollection <Recommendation> recs = new List <Recommendation>();

            foreach (long groupId in groups)
            {
                Recommendation r = RecommendationDao.FindByGroupIdAndEventIdAndUsrId(groupId, userId, eventId);
                if (r != null)
                {
                    r.reason = description;
                    RecommendationDao.Update(r);
                }
                else
                {
                    UserGroup      g   = GroupDao.Find(groupId);
                    UserProfile    u   = UserProfileDao.Find(userId);
                    Recommendation rec = new Recommendation();
                    rec.UserGroup   = g;
                    rec.UserProfile = u;
                    rec.Event       = e;
                    rec.reason      = description;
                    RecommendationDao.Create(rec);
                    recs.Add(rec);
                }
            }
            return(recs);
        }
コード例 #6
0
        public CardDetails GetUserDefaultCard(long userProfileId)
        {
            CardDetails defaultCard = null;
            UserProfile user        = null;

            try
            {
                user = UserProfileDao.Find(userProfileId);
            } catch (InstanceNotFoundException e)
            {
                throw new InstanceNotFoundException(userProfileId, "Usuario no encontrado");
            }
            List <Card> userCards = user.Cards.ToList();

            if (userCards != null)
            {
                for (int i = 0; i < userCards.Count; i++)
                {
                    if (userCards.ElementAt(i).defaultCard)
                    {
                        string   cardNumber = userCards.ElementAt(i).cardNumber;
                        string   cardType   = userCards.ElementAt(i).cardType;
                        int      cv         = userCards.ElementAt(i).verificationCode;
                        bool     defaultC   = userCards.ElementAt(i).defaultCard;
                        long     cardId     = userCards.ElementAt(i).idCard;
                        DateTime date       = userCards.ElementAt(i).expirationDate;
                        defaultCard = new CardDetails(cardNumber, cv, date, cardType, cardId, defaultC);
                    }
                }
            }
            return(defaultCard);
        }
コード例 #7
0
        public int GetRating(long userId, long linkId)
        {
            if (!UserProfileDao.Exists(userId))
            {
                throw new InstanceNotFoundException <UserProfileDetails>("userId", userId);
            }

            if (!LinkDao.Exists(linkId))
            {
                throw new InstanceNotFoundException <LinkDetails>("linkId", linkId);
            }

            try
            {
                return(RatingDao.FindForUserAndLink(userId, linkId).value);
            }
            catch (InstanceNotFoundException <Rating> )
            {
                return(0);
            }
            catch (DuplicateInstanceException <Rating> ex)
            {
                throw new InternalErrorException(ex);
            }
        }
コード例 #8
0
        /// <exception cref="InstanceNotFoundException">If productoId doesn't exist</exception>
        public ComentarioEtiquetaBlock AddComentarioEtiqueta(long usrId, long productoId, string textoComentario, List <string> tags)
        {
            if (productoId == -1)
            {
                throw new InstanceNotFoundException(productoId, "producto");
            }
            Comentario comentario = Comentario.CreateComentario(-1, textoComentario, DateTime.Now, usrId, productoId);

            comentario.UserProfile = UserProfileDao.Find(usrId);
            ComentarioDao.Create(comentario);
            List <Etiqueta> etiquetas = new List <Etiqueta>();

            if (tags != null)
            {
                int num = tags.Count();

                for (int i = 0; i < num; i++)
                {
                    etiquetas.Add(AddEtiqueta(tags[i]));
                    Etiquetar(comentario.comentarioId, etiquetas[i].etiquetaId);
                }
            }
            else
            {
                etiquetas = null;
            }
            ComentarioEtiquetaBlock comEtiBlock = new ComentarioEtiquetaBlock(comentario, etiquetas);

            return(comEtiBlock);
        }
コード例 #9
0
ファイル: UserService.cs プロジェクト: lob94/Mad
        public long RegisterUser(string loginName, string clearPassword,
                                 UserProfileDetails userProfileDetails)
        {
            try
            {
                UserProfileDao.FindByLoginName(loginName);

                throw new DuplicateInstanceException(loginName,
                                                     typeof(UserProfile).FullName);
            }
            catch (InstanceNotFoundException)
            {
                String encryptedPassword = PasswordEncrypter.Crypt(clearPassword);

                UserProfile userProfile = new UserProfile();

                userProfile.loginName  = loginName;
                userProfile.enPassword = encryptedPassword;
                userProfile.firstName  = userProfileDetails.FirstName;
                userProfile.lastName   = userProfileDetails.Lastname;
                userProfile.email      = userProfileDetails.Email;
                userProfile.language   = userProfileDetails.Language;
                userProfile.country    = userProfileDetails.Country;

                UserProfileDao.Create(userProfile);

                return(userProfile.usrId);
            }
        }
コード例 #10
0
ファイル: UserService.cs プロジェクト: lob94/Mad
        public LoginResult Login(string loginName, string password, bool passwordIsEncrypted)
        {
            UserProfile userProfile =
                UserProfileDao.FindByLoginName(loginName);

            String storedPassword = userProfile.enPassword;

            if (passwordIsEncrypted)
            {
                if (!password.Equals(storedPassword))
                {
                    throw new IncorrectPasswordException(loginName);
                }
            }
            else
            {
                if (!PasswordEncrypter.IsClearPasswordCorrect(password,
                                                              storedPassword))
                {
                    throw new IncorrectPasswordException(loginName);
                }
            }

            return(new LoginResult(userProfile.usrId, userProfile.firstName,
                                   storedPassword, userProfile.language, userProfile.country));
        }
コード例 #11
0
        /// <exception cref="InstanceNotFoundException">If usrId doesn't match an existing UserProfile</exception>
        public Favorito AddFavorito(long usrId, long productoId, string bookmark, string comentario)
        {
            Favorito favorito = Favorito.CreateFavorito(-1, bookmark, DateTime.Now, comentario, usrId, productoId);

            favorito.UserProfile = UserProfileDao.Find(usrId);
            FavoritoDao.Create(favorito);
            return(favorito);
        }
コード例 #12
0
        public int CountFavoritesForUser(long userId)
        {
            if (!UserProfileDao.Exists(userId))
            {
                throw new InstanceNotFoundException <UserProfileDetails>("userId", userId);
            }

            return(FavoriteDao.CountForUser(userId));
        }
コード例 #13
0
ファイル: UserService.cs プロジェクト: lob94/Mad
        public UserGroup UnJoinGroup(long userId, long groupId)
        {
            UserGroup   group = GroupDao.Find(groupId);
            UserProfile user  = UserProfileDao.Find(userId);

            group.UserProfiles.Remove(user);
            GroupDao.Update(group);
            return(group);
        }
コード例 #14
0
ファイル: UserService.cs プロジェクト: lob94/Mad
        public UserGroup AddGroup(string name, string description, long userId)
        {
            UserProfile u = UserProfileDao.Find(userId);
            UserGroup   g = new UserGroup();

            g.name        = name;
            g.description = description;
            g.UserProfiles.Add(u);
            GroupDao.Create(g);
            return(g);
        }
コード例 #15
0
ファイル: UserService.cs プロジェクト: lob94/Mad
        public UserProfileDetails FindUserProfileDetails(long userProfileId)
        {
            UserProfile userProfile = UserProfileDao.Find(userProfileId);

            UserProfileDetails userProfileDetails =
                new UserProfileDetails(userProfile.firstName,
                                       userProfile.lastName, userProfile.email,
                                       userProfile.language, userProfile.country);

            return(userProfileDetails);
        }
コード例 #16
0
        /// <exception cref="InstanceNotFoundException">If usrId doesn't match an existing UserProfile</exception>
        public Valoracion ValorarUsuario(string vendedorId, long usrId, int voto, string text)
        {
            Valoracion valoracion = Valoracion.CreateValoracion(-1, voto, DateTime.Now, usrId, vendedorId);

            if (text != null)
            {
                valoracion.comentario = text;
            }
            valoracion.UserProfile = UserProfileDao.Find(usrId);
            ValoracionDao.Create(valoracion);
            return(valoracion);
        }
コード例 #17
0
ファイル: UserService.cs プロジェクト: lob94/Mad
        public ICollection <UserGroupDto> FindGroupsByUserId(long userId)
        {
            UserProfile                user      = UserProfileDao.Find(userId);
            ICollection <UserGroup>    groups    = user.UserGroups;
            ICollection <UserGroupDto> groupsDto = new List <UserGroupDto>();

            foreach (UserGroup group in groups)
            {
                groupsDto.Add(new UserGroupDto(group));
            }
            return(groupsDto);
        }
コード例 #18
0
        /// <summary>
        /// Checks if the specified loginName corresponds to a valid user.
        /// </summary>
        /// <param name="loginName"> User loginName. </param>
        /// <returns> Boolean to indicate if the loginName exists </returns>
        public bool UserExists(string loginName)
        {
            try
            {
                UserProfile userProfile = UserProfileDao.FindByLoginName(loginName);
            }
            catch (InstanceNotFoundException)
            {
                return(false);
            }

            return(true);
        }
コード例 #19
0
        public int GetOrdersByUser(long usrId)
        {
            int n = 0;

            try
            {
                n = UserProfileDao.Find(usrId).Orders.Count;
            } catch (InstanceNotFoundException e)
            {
                throw new InstanceNotFoundException(usrId, "Usuario no encontrado");
            }
            return(n);
        }
コード例 #20
0
ファイル: UserService.cs プロジェクト: lob94/Mad
        public void UpdateUserProfileDetails(long userProfileId,
                                             UserProfileDetails userProfileDetails)
        {
            UserProfile userProfile =
                UserProfileDao.Find(userProfileId);

            userProfile.firstName = userProfileDetails.FirstName;
            userProfile.lastName  = userProfileDetails.Lastname;
            userProfile.email     = userProfileDetails.Email;
            userProfile.language  = userProfileDetails.Language;
            userProfile.country   = userProfileDetails.Country;
            UserProfileDao.Update(userProfile);
        }
コード例 #21
0
        public int GetNumberOfCardsByUser(long userProfileId)
        {
            int n = 0;

            try
            {
                n = UserProfileDao.Find(userProfileId).Cards.ToList <Card>().Count;
            }
            catch (InstanceNotFoundException e) {
                throw new InstanceNotFoundException(userProfileId, "Usuario no encontrado");
            }
            return(n);
        }
コード例 #22
0
        /// <summary>
        /// Check if User exists, if not throw exception
        /// </summary>
        /// <param name="loginName"><c>loginName</c> User login name.</param>
        /// <returns>UserProfile.</returns>
        /// <exception cref="UserNotFoundException"/>
        private UserProfile CheckUser(string loginName)
        {
            UserProfile user;

            try
            {
                user = UserProfileDao.FindByLoginName(loginName);
            }
            catch (InstanceNotFoundException)
            {
                throw new UserNotFoundException(loginName);
            }
            return(user);
        }
コード例 #23
0
        public bool HasInFavorites(long userId, long linkId)
        {
            if (!UserProfileDao.Exists(userId))
            {
                throw new InstanceNotFoundException <UserProfileDetails>("userId", userId);
            }

            if (!LinkDao.Exists(linkId))
            {
                throw new InstanceNotFoundException <LinkDetails>("linkId", linkId);
            }

            return(FavoriteDao.ExistsForUserAndLink(userId, linkId));
        }
コード例 #24
0
        public Delivery CreateDelivery(decimal deliveryPrice, long cardNumber, long userId, string description,
                                       List <ShoppingCart> shoppingCart, string deliveryAddress = null)
        {
            CreditCard card = CreditCardDao.FindByNumber(cardNumber);

            if (CreditCardDao.FindByUserId(userId)
                .Contains(card))
            {
                Delivery delivery = new Delivery
                {
                    deliveryDate    = DateTime.Now,
                    deliveryPrice   = deliveryPrice,
                    deliveryAddress = deliveryAddress ?? UserProfileDao.Find(userId).address,
                    cardId          = card.cardId,
                    userId          = userId,
                    description     = description
                };

                DeliveryDao.Create(delivery);

                DeliveryLine deliveryLine;
                foreach (ShoppingCart item in shoppingCart)
                {
                    deliveryLine = new DeliveryLine();

                    if (item.Product.productQuantity - item.Amount >= 0)
                    {
                        DecreaseProductStock(item.Product, item.Amount);
                        deliveryLine.deliveryLineAmount = item.Amount;
                    }
                    else
                    {
                        throw new StockEmptyException(item.Product.productId, item.Product.productName);
                    }

                    deliveryLine.deliveryLinePrice = item.Product.productPrice;
                    deliveryLine.productId         = item.Product.productId;
                    deliveryLine.deliveryId        = delivery.deliveryId;

                    DeliveryLineDao.Create(deliveryLine);
                }

                return(delivery);
            }
            else
            {
                throw new UnmatchingUserAndCardException(userId, cardNumber);
            }
        }
コード例 #25
0
        public void UpdateUserProfileDetails(long userProfileId,
                                             UserProfileDetails userProfileDetails)
        {
            UserProfile userProfile =
                UserProfileDao.Find(userProfileId);

            userProfile.firstName = userProfileDetails.firstName;
            userProfile.lastName  = userProfileDetails.lastName;
            userProfile.email     = userProfileDetails.email;
            userProfile.language  = userProfileDetails.language;
            userProfile.country   = userProfileDetails.country;
            userProfile.role      = userProfileDetails.role;
            userProfile.address   = userProfileDetails.address;
            UserProfileDao.Update(userProfile);
        }
コード例 #26
0
        public Comment AddComment(string comment, long eventId, long userId)
        {
            Event       e = EventDao.Find(eventId);
            UserProfile u = UserProfileDao.Find(userId);

            Comment c = new Comment();

            c.content     = comment;
            c.Event       = e;
            c.UserProfile = u;
            c.commentDate = DateTime.Now;
            c.Labels      = new List <Label>();
            c.loginName   = u.loginName;
            CommentDao.Create(c);

            return(c);
        }
コード例 #27
0
ファイル: UserService.cs プロジェクト: lob94/Mad
        public void ChangePassword(long userProfileId, string oldClearPassword,
                                   string newClearPassword)
        {
            UserProfile userProfile    = UserProfileDao.Find(userProfileId);
            String      storedPassword = userProfile.enPassword;

            if (!PasswordEncrypter.IsClearPasswordCorrect(oldClearPassword,
                                                          storedPassword))
            {
                throw new IncorrectPasswordException(userProfile.loginName);
            }

            userProfile.enPassword =
                PasswordEncrypter.Crypt(newClearPassword);

            UserProfileDao.Update(userProfile);
        }
コード例 #28
0
        public List <DTOComment> FindComments(long eventId, int startIndex, int count)
        {
            List <DTOComment> result = new List <DTOComment>();

            if (!SportEventDao.Exists(eventId))
            {
                throw new EventNotExistsException(eventId);
            }

            List <Comment> listComment = CommentDao.FindCommentsByEventIdOrderByDate(eventId, startIndex, count);
            UserProfile    userOwner;

            foreach (var comment in listComment)
            {
                userOwner = UserProfileDao.Find(comment.ownerId);
                result.Add(new DTOComment(comment.commentId, userOwner.loginName, comment.eventId,
                                          comment.comment_description, comment.publishDate, tagsToListOfStrings(comment.Tags.ToList())));
            }
            return(result);
        }
コード例 #29
0
        public void UpdateFavorite(long userId, long linkId, string name, string description)
        {
            if (!UserProfileDao.Exists(userId))
            {
                throw new InstanceNotFoundException <UserProfileDetails>("userId", userId);
            }

            if (!LinkDao.Exists(linkId))
            {
                throw new InstanceNotFoundException <LinkDetails>("linkId", linkId);
            }

            Favorite favorite;

            try
            {
                favorite = FavoriteDao.FindForUserAndLink(userId, linkId);
            }
            catch (InstanceNotFoundException <Favorite> ex)
            {
                throw new InstanceNotFoundException <FavoriteDetails>(ex.Properties);
            }
            catch (DuplicateInstanceException <Favorite> ex)
            {
                throw new InternalErrorException(ex);
            }

            favorite.name        = name;
            favorite.description = description;

            try
            {
                FavoriteDao.Update(favorite);
            }
            catch (InstanceNotFoundException <Favorite> ex)
            {
                throw new InternalErrorException(ex);
            }
        }
コード例 #30
0
ファイル: UserService.cs プロジェクト: lob94/Mad
        public ICollection <RecommendationDto> FindGroupRecommendations(long groupId, long userId, int startIndex, int count)
        {
            UserProfile u = UserProfileDao.Find(userId);
            UserGroup   g = GroupDao.Find(groupId);

            if (g.UserProfiles.Contains(u))
            {
                ICollection <Recommendation>    recs    = RecommendationDao.FindByGroupId(groupId, startIndex, count);
                ICollection <RecommendationDto> recsDto = new List <RecommendationDto>();

                foreach (Recommendation r in recs)
                {
                    Event e = EventDao.Find(r.eventId);
                    recsDto.Add(new RecommendationDto(r, e.name));
                }
                return(recsDto);
            }
            else
            {
                throw new Exception();
            }
        }