/// <summary> /// Permet d'ajout un film dans la liste de souhait, ou ajouter /// un utilisateur sur le film déjà souhaité. /// </summary> /// <param name="movie"></param> /// <param name="idUser"></param> public void AddMovie(MovieWishModel movie, Guid idUser) { if (HaveMovieInWish(movie.IdVideoTmDb)) { // Ajout de l'utilisateur dans la liste WishModel wish = _wishListModels.FirstOrDefault(x => x.Movie.IdVideoTmDb == movie.IdVideoTmDb); if (wish != null) { if (!wish.HasUserId(idUser)) { wish.IdUsers.Add(idUser); _storage.SaveWishModels(_wishListModels); } } } else { // Ajout du film dans la liste de Souhait. WishModel model = new WishModel(movie, new List <Guid>() { idUser }); _wishListModels.Add(model); _storage.SaveWishModels(_wishListModels); } }
public async Task Notify(WishModel model) { _logger.LogInformation("Processing gift : {giftId}", model.Id); var message = $"new wish just arrived, please - {model.Who} wants {model.Type} - {model.Description}. Gift needs to be shipped to {model.Address}"; _logger.LogInformation("Sending gift : {giftId} - {message}", model.Id, message); using var client = _httpClientFactory.CreateClient(); var response = await client.SendAsync(new HttpRequestMessage() { Method = HttpMethod.Post, RequestUri = new Uri(_options.Url), Content = new StringContent( JsonConvert.SerializeObject( new SlackModel { Text = message }, new JsonSerializerSettings() { ContractResolver = new CamelCasePropertyNamesContractResolver() })) }); response.EnsureSuccessStatusCode(); }
private async Task <Result <WishModel> > Insert(int userId, IEnumerable <WishCreationModel> wishCreationModel) { foreach (var wishItem in wishCreationModel) { this.wishRepository.Add(Wish.Create(userId, wishItem.IdProduct).Value); } unitOfWork.Save(); var products = new List <ProductModel>(); foreach (var i in wishCreationModel) { products.Add(await this.productQueryRepository.GetById(i.IdProduct)); } var model = new WishModel { Id = userId, Products = products, }; var indexResult = await this.indexService.IndexDocumentAsync(model); if (indexResult.Failure) { await RollbackInsert(userId, wishCreationModel); return(OperationResult.InternalServerError <WishModel>(indexResult)); } return(OperationResult.Created(model)); }
public async Task EditWish(int id, WishModel wish) { string sqlCommand = @"UPDATE Wish SET ITEM_TITLE = @ITEM_TITLE, ITEM_DESCRIPTION = @ITEM_DESCRIPTION WHERE WISH_ID=@WISH_ID;"; await _db.SaveData(sqlCommand, new { WISH_ID = id, ITEM_TITLE = wish.ITEM_TITLE, ITEM_DESCRIPTION = wish.ITEM_DESCRIPTION }); }
public WishView(IRegion mainRegion) { InitializeComponent(); SetInputGestures(); SetSyntaxHighlighting(); _mainRegion = mainRegion; _wishModel = new WishModel(); _state = new Normal(_wishModel); }
/// <summary> /// Update wishlist if has items, else delete wishlist /// </summary> /// <param name="wish"></param> /// <returns></returns> private async Task <Result> UpdateOrDeleteWishListInIndexService(WishModel wish) { if (wish.Products.Any()) { return(await this.indexService.UpdateDocumentAsync(wish.Id, wish)); } return(await this.indexService.DeleteDocumentAsync(wish.Id)); }
public async Task <WishModel> GetByID(int id) { string sql = @"SELECT WISH_ID, ITEM_TITLE, ITEM_DESCRIPTION, GRANTED, GRANTED_BY FROM Wish WHERE WISH_ID=@WISH_ID;"; var wish_query = await _db.LoadData <WishModel, dynamic>(sql, new { WISH_ID = id }); WishModel wish = wish_query.FirstOrDefault(); return(wish); }
/// <summary> /// Check if the new items already exist in wishlist /// </summary> /// <param name="wish"></param> /// <param name="newWishListItems"></param> /// <returns></returns> private Result IfWishItemsExistsInWishList(WishModel wish, IEnumerable <int> newWishListItems) { var itemsAlreadyExists = wish.Products.Select(x => x.Id).Intersect(newWishListItems); if (itemsAlreadyExists.Any()) { return(OperationResult.Conflict($"The product(s) {string.Join(",", itemsAlreadyExists)} already exist in user {wish.Id} wishlist")); } return(OperationResult.OK()); }
public async Task GrantWish(int id, WishModel wish) { string sql_username = @"SELECT * FROM Account where ACCOUNT_ID=@ACCOUNT_ID"; var acc_query = await _db.LoadData <AccountModel, dynamic>(sql_username, new { ACCOUNT_ID = id }); AccountModel acc = acc_query.FirstOrDefault(); string username = acc.USERNAME; string sqlCommand = @"UPDATE Wish SET GRANTED=1, GRANTED_BY=@GRANTED_BY WHERE WISH_ID=@WISH_ID;"; await _db.SaveData(sqlCommand, new { WISH_ID = wish.WISH_ID, GRANTED_BY = username }); }
private async Task RollbackUpdate(WishModel wishModel, IEnumerable <WishCreationModel> wishCreationModel) { var wish = await this.wishQueryRepository.GetByUser(wishModel.Id); foreach (var wishItem in wishCreationModel) { var toRemove = wish.Products.Find(x => x.Id == wishItem.IdProduct); wish.Products.Remove(toRemove); } await this.indexService.UpdateDocumentAsync(wish.Id, wish); this.wishRepository.RemoveItems(wishModel.Id, wishCreationModel.Select(x => x.IdProduct)); this.unitOfWork.Save(); }
public IHttpActionResult RemoveWish([FromBody] WishModel i_Wish) { LogControllerEntring("remove"); IHttpActionResult result = Ok(); try { using (MyDiveEntities MyDiveDB = new MyDiveEntities()) { int?wishID = -1; wishID = MyDiveDB.stp_RemoveFromWishList(i_Wish.UserID, i_Wish.SiteID); LogData("remove wish", i_Wish); result = Ok(wishID != -1 ? wishID : null); } } catch (Exception ex) { result = LogException(ex, null); } return(result); }
/// <inheritdoc /> public void RemoveMovie(int idMovie, string userId) { if (HaveMovieInWish(idMovie, userId)) { WishModel wish = _wishListModels.FirstOrDefault(x => x.Movie.IdVideoTmDb == idMovie); if (wish != null) { if (wish.HasUserId(userId)) { wish.IdUsers.Remove(Guid.Parse(userId)); if (wish.IdUsers.Count == 0) { _wishListModels.Remove(wish); } _storage.SaveWishModels(_wishListModels); } } } }
/// <summary> /// Permet de supprimer un utilisateur d'un film souhaité, /// et si plus aucun utilisateur, enlever le film de la liste. /// </summary> /// <param name="movie"></param> /// <param name="idUser"></param> public void RemoveMovie(MovieWishModel movie, Guid idUser) { if (HaveMovieInWish(movie.IdVideoTmDb)) { WishModel wish = _wishListModels.FirstOrDefault(x => x.Movie.IdVideoTmDb == movie.IdVideoTmDb); if (wish != null) { if (wish.HasUserId(idUser)) { wish.IdUsers.Remove(idUser); if (wish.IdUsers.Count == 0) { _wishListModels.Remove(wish); } _storage.SaveWishModels(_wishListModels); } } } }
private async Task <Result <WishModel> > Update(WishModel wish, IEnumerable <WishCreationModel> wishCreationModel) { var productsIds = wishCreationModel.Select(x => x.IdProduct); var existsItemsResult = IfWishItemsExistsInWishList(wish, productsIds); if (existsItemsResult.Failure) { return(OperationResult.NotFound <WishModel>(existsItemsResult)); } foreach (var wishItem in productsIds) { this.wishRepository.Add(Wish.Create(wish.Id, wishItem).Value); } unitOfWork.Save(); var products = new List <ProductModel>(); foreach (var i in wishCreationModel) { products.Add(await this.productQueryRepository.GetById(i.IdProduct)); } wish.Products.AddRange(products); var indexResult = await this.indexService.UpdateDocumentAsync(wish.Id, wish); if (indexResult.Failure) { await RollbackUpdate(wish, wishCreationModel); return(OperationResult.InternalServerError <WishModel>(indexResult)); } return(OperationResult.NoContent <WishModel>()); }
public Completion(WishModel wishModel) { _wishModel = wishModel; }
public Normal(WishModel wishModel) { _wishModel = wishModel; }
public async Task AddWish(int id, WishModel wish) { string sqlCommand = @"INSERT INTO Wish(FK_ACCOUNT_ID, ITEM_TITLE, ITEM_DESCRIPTION) VALUES(@FK_ACCOUNT_ID, @ITEM_TITLE, @ITEM_DESCRIPTION);"; await _db.SaveData(sqlCommand, new { FK_ACCOUNT_ID = id, ITEM_TITLE = wish.ITEM_TITLE, ITEM_DESCRIPTION = wish.ITEM_DESCRIPTION }); }