public async Task <IEnumerable <WishDTO> > GetAllWishes(int userId, [FromUri] int page_size, [FromUri] int page) { List <WishDTO> wishesModel = new List <WishDTO>(); PaginationParameter paginationParameter = new PaginationParameter(page, page_size); IList <Wish> wishes = await _servico.ListWishesAsync(paginationParameter, userId); // Faz a troca de dados da classe de dominio para a classe de exibicao if (wishes != null && wishes.Count > 0) { foreach (Wish wish in wishes) { if (wish.User == null || wish.Product == null) { continue; } WishDTO wm = new WishDTO(); wm.id = userId; wm.name = wish.Product.Name; wishesModel.Add(wm); } } return(wishesModel); }
public WishDTO GetSingleWish(string stringId) { Guid wishId = Helper.SafeGuidParse(stringId); if (wishId == new Guid()) { Helper.MyPrint("Error: Invalid Wish id.", "r"); return(null); } else { List <Wish> allWishes = this.db.GetAllWish(); List <Product> allProd = this.db.GetAllProduct(); List <WishList> allWishLists = this.db.GetAllWishList(); List <ProductDTO> allProducts = new List <ProductDTO>(); allProd.ForEach(delegate(Product product) { allProducts.Add(ModelToDTOMapper.ProductMapper(product)); }); WishDTO wishDTO = new WishDTO(); Wish wish = this.db.GetSingleWish(Helper.SafeGuidParse(stringId)); if (wish != null) { return(this.GetFullWishWithItems(wish, allWishes, allProducts, allWishLists)); } } return(null); }
public void ShowWishListPrice() { this.ShowAllWish(); Console.WriteLine("Enter Wish list id:"); string wishIdString = Console.ReadLine().Trim(); WishDTO wish = this.wishService.GetSingleWish(wishIdString); if (wish != null) { double totalWishPrice = 0; foreach (ProductDTO product in wish.Items) { totalWishPrice += product.Price; } Console.WriteLine("Enter discout codes, seperated by spaces"); string discountKeys = Console.ReadLine().Trim(); IDecoratorComponent decorator = wish; foreach (string coupon in discountKeys.Split(" ")) { if (coupon != "") { if (this.coupons.ContainsKey(coupon)) { if (coupon == "drop10") { decorator = new Discount10(decorator); //Helper.MyPrint(decorator.GetPrice().ToString()); } else if (coupon == "drop20") { decorator = new Discount20(decorator); //Helper.MyPrint(decorator.GetPrice().ToString()); } else if (coupon == "drop50") { decorator = new Discount50(decorator); //Helper.MyPrint(decorator.GetPrice().ToString()); } } else { Helper.MyPrint($"Error: {coupon} doesn't exist.", "r"); } } } //decorator = new Discount(wish); Helper.MyPrint($"Your total wish will cost {decorator.GetPrice()} taka.", "g"); } }
public IHttpActionResult GetWish(int id) { try { WishDTO wishDTO = travelService.GetWish(id); Mapper.Initialize(cfg => cfg.CreateMap <WishDTO, WishViewModel>()); var wish = Mapper.Map <WishDTO, WishViewModel>(wishDTO); return(Ok(wish)); } catch (ValidationException ex) { return(Content(HttpStatusCode.BadRequest, ex.Message)); } }
public void ViewSingleWish() { Console.WriteLine("Enter the wish id you want to see: "); Console.WriteLine("Enter -1 to go back: "); string idString = Console.ReadLine().Trim(); WishDTO wish = this.wishService.GetSingleWish(idString); if (wish == null) { Helper.MyPrint("No wish found."); } else { wish.Display(); } }
public void AddTripReport(WishDTO wish, double?reiting, DateTime date) { Trip trip = new Trip { DateTrip = date, UserName = wish.UserName, CityId = wish.CityId }; Dbase.Trips.Create(trip); //Change city reiting and counter City city = Dbase.Cities.Get(wish.CityId); if (reiting != null) { double?reitingOld = city.Reiting; int? countVisitors = city.CountVisitors; double?reitingNew = (reitingOld * countVisitors + reiting) / (countVisitors + 1); city.Reiting = reitingNew; } city.CountVisitors++; Dbase.Cities.Update(city); }