Пример #1
0
        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);
        }
Пример #2
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);
        }
Пример #3
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);
        }
Пример #4
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);
        }
Пример #5
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);
        }
Пример #6
0
        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);
        }
Пример #7
0
        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);
        }
Пример #8
0
        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);
        }
Пример #9
0
        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);
        }
Пример #10
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);
        }
Пример #11
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);
        }
Пример #12
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);
        }
Пример #13
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;
            UserProfileDao.Update(userProfile);
        }
Пример #14
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);
            }
        }
Пример #15
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);
        }
Пример #16
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);
        }
Пример #17
0
        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);
        }
Пример #18
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);
        }
Пример #19
0
        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();
            }
        }
Пример #20
0
        public List <CardDetails> ViewCardsByUser(long userProfileId, int startIndex, int count)
        {
            List <CardDetails> userCards = new List <CardDetails>();

            List <Card> cards = null;
            UserProfile user  = null;

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

            cards = user.Cards.ToList <Card>();
            int c = 0;

            for (int i = startIndex; i < cards.Count; i++)
            {
                if (c == count)
                {
                    break;
                }
                string   cardNumber     = cards.ElementAt(i).cardNumber;
                int      cv             = cards.ElementAt(i).verificationCode;
                DateTime expirationDate = cards.ElementAt(i).expirationDate;
                string   type           = cards.ElementAt(i).cardType;
                bool     defaultCard    = cards.ElementAt(i).defaultCard;
                long     cardId         = cards.ElementAt(i).idCard;
                userCards.Add(new CardDetails(cardNumber, cv, expirationDate, type, cardId, defaultCard));
                c++;
            }
            return(userCards);
        }
Пример #21
0
        public void AddCard(long userProfileId, CardDetails newCard)
        {
            UserProfile UserProfile = UserProfileDao.Find(userProfileId);

            try
            {
                CardDao.FindByCardNumber(newCard.CardNumber);
                throw new DuplicateInstanceException(newCard.CardNumber,
                                                     typeof(Card).FullName);
            } catch (InstanceNotFoundException)
            {
                long number1    = 0;
                bool canConvert = long.TryParse(newCard.CardNumber, out number1);
                if (!canConvert)
                {
                    throw new IncorrectCardNumberFormatException(newCard.CardNumber);
                }
                Card creditCard = new Card();
                creditCard.usrId            = UserProfile.usrId;
                creditCard.cardNumber       = newCard.CardNumber;
                creditCard.verificationCode = newCard.VerificationCode;
                creditCard.expirationDate   = newCard.ExpirateTime;
                creditCard.cardType         = newCard.CardType;

                if (!UserProfile.Cards.Any())
                {
                    creditCard.defaultCard = true;
                }
                else
                {
                    creditCard.defaultCard = false;
                }

                CardDao.Create(creditCard);
            }
        }
Пример #22
0
        public List <OrderDetails> ViewOrdersByUser(long usrId, int startIndex, int count)
        {
            UserProfile User = UserProfileDao.Find(usrId);

            List <OrderDetails> ordersDetails = new List <OrderDetails>();

            List <Order> orders = User.Orders.ToList();

            int c = 0;

            for (int i = startIndex; i < orders.Count; i++)
            {
                if (c == count)
                {
                    break;
                }
                List <OrderLine> orderLines = orders.ElementAt(i).OrderLines.ToList();

                List <OrderLineDetails> orderLinesDetails = new List <OrderLineDetails>();
                for (int j = 0; j < orderLines.Count; j++)
                {
                    string           productName   = orderLines.ElementAt(j).Product.name;
                    int              numberOfUnits = orderLines.ElementAt(j).numberOfUnits;
                    float            unitPrize     = (float)orderLines.ElementAt(j).unitPrize;
                    OrderLineDetails orderLine     = new OrderLineDetails(orders.ElementAt(i).orderId, productName, numberOfUnits, unitPrize);
                    orderLinesDetails.Add(orderLine);
                }
                long     orderId       = orders.ElementAt(i).orderId;
                string   cardNumber    = CardDao.Find(orders.ElementAt(i).idCard).cardNumber;
                int      postalAddress = orders.ElementAt(i).postalAddress;
                DateTime orderDate     = orders.ElementAt(i).orderDate;
                ordersDetails.Add(new OrderDetails(orderId, usrId, cardNumber, postalAddress, orderDate, orderLinesDetails));
                c++;
            }
            return(ordersDetails);
        }