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)); }
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); }
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)); }
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); }
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); }
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); }
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); } }
/// <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); }
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); } }
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)); }
/// <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); }
public int CountFavoritesForUser(long userId) { if (!UserProfileDao.Exists(userId)) { throw new InstanceNotFoundException <UserProfileDetails>("userId", userId); } return(FavoriteDao.CountForUser(userId)); }
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); }
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); }
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); }
/// <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); }
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); }
/// <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); }
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); }
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); }
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); }
/// <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); }
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)); }
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); } }
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); }
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); }
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); }
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); }
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); } }
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(); } }