コード例 #1
0
        public async Task DeleteWineById() // ** review **
        {
            // Arrange
            var newWineModel = new WineModel
            {
                Name        = "Rioja",
                RegionId    = 5,
                Sparkling   = false,
                Price       = 4.7M,
                Description = "Red"
            };

            var addWine = await _wineService.AddNewWine(newWineModel);

            // Act
            var delWine = await _wineService.DeleteWineById(addWine.ID);

            // Assert
            Assert.IsNotNull(delWine);


            ////test passed
            //var findWine = await _wineService.GetWineById(27);

            //var delWine = await _wineService.DeleteWineById(findWine.ID);

            //Assert.IsNotNull(delWine);
        }
コード例 #2
0
        public static WineModel Map(Wine wine)
        {
            WineModel model = null;

            if (wine != null)
            {
                model = new WineModel
                {
                    Id = wine.Id,
                    Country = wine.Country,
                    Name = wine.Name,
                    PhotoPath = new BitmapImage(new System.Uri( Globals.ServiceHostUrl + "/content/images/wines/" + wine.PhotoPath)),
                    Type = wine.Type,
                    Varietal = wine.Varietal,
                    Vineyard = wine.Vineyard,
                    Year = wine.Year,
                    Comments = wine.Comments,
                    Pairing = wine.Pairing,
                    PriceRange = wine.PriceRange,
                    CreateDate = wine.CreateDate
                };

                model.BusinessOwner = Mapper.Map(wine.BusinessOwner);
            }

            return model;
        }
コード例 #3
0
        public static Wine Map(WineModel wineModel)
        {
            Wine wine = null;

            if (wineModel != null)
            {
                wine = new Wine
                {
                    Id = 0,
                    Country = wineModel.Country,
                    Name = wineModel.Name,
                    //hotoPath = wineModel.PhotoPath,
                    Type = wineModel.Type,
                    Varietal = wineModel.Varietal,
                    Vineyard = wineModel.Vineyard,
                    Year = wineModel.Year,
                    Comments = wineModel.Comments,
                    Pairing = wineModel.Pairing,
                    PriceRange = wineModel.PriceRange,
                };

                wine.BusinessOwner = new Business { Id = wineModel.BusinessOwner.Id };
            }

            return wine;
        }
コード例 #4
0
 private void LoadWine( string wineId )
 {
     IsLoading = true;
     var wineProxy = new WineProxy();
     wineProxy.GetWineDetail( wineId, callback => SmartDispatcher.BeginInvoke( () =>
     {
         IsLoading = false;
         WineModel = callback;
     } ) );
 }
コード例 #5
0
 public IHttpActionResult GetWineByCategory(int categoryId)
 {
     try
     {
         return(Ok(WineModel.GetWineByCategory(categoryId, db)));
     }
     catch (Exception ex)
     {
         return(Content(HttpStatusCode.BadRequest, ex.InnerException));
     }
 }
コード例 #6
0
 public IHttpActionResult Get(int Wineryid)
 {
     try
     {
         return(Ok(WineModel.GetAllWineInWinery(Wineryid, db)));
     }
     catch (Exception ex)
     {
         return(Content(HttpStatusCode.BadRequest, ex));
     }
 }
コード例 #7
0
 public IHttpActionResult GetWineryWinesComments(int Id)
 {
     try
     {
         return(Ok(WineModel.GetAllWineryWineComments(Id, db)));
     }
     catch (Exception ex)
     {
         return(Content(HttpStatusCode.BadRequest, ex));
     }
 }
コード例 #8
0
 public ActionResult SaveAndUpdate(WineModel wnModel)
 {
     if (wnModel.ID == 0)
     {
         HttpResponseMessage response = APIContent.Client.PostAsJsonAsync("Wines", wnModel).Result;
         TempData["SuccessMessage"] = "Saved Successfully";
     }
     else
     {
         HttpResponseMessage response = APIContent.Client.PutAsJsonAsync("Wines/" + wnModel.ID, wnModel).Result;
         TempData["SuccessMessage"] = "Updated Successfully";
     }
     return(RedirectToAction("Index"));
 }
コード例 #9
0
        public void FluentValidation()
        {
            // Arrange
            var testWine = new WineModel {
                ID = 1, Name = "Test", Price = 6.70M, Description = "nothing", RegionId = 1, Sparkling = false
            };
            FluentFiguresValidator validator = new FluentFiguresValidator();

            // Act
            var result = validator.Validate(testWine);


            // Assert
            Assert.IsTrue(result.IsValid);
        }
コード例 #10
0
        // update
        public async Task <WineModel> UpdateWineById(WineModel updModel)
        {
            var findModel = await _repository.GetSingleAsync <Wine.Data.Wine>(x => x.ID == updModel.ID);

            findModel.Name        = updModel.Name;
            findModel.RegionId    = updModel.RegionId;
            findModel.Price       = updModel.Price;
            findModel.Description = updModel.Description;
            findModel.Sparkling   = updModel.Sparkling;

            _repository.Update <Wine.Data.Wine>(findModel);

            await _repository.CommitAsync();

            return(updModel);
        }
コード例 #11
0
        public void SaveNewWine(WineModel wineModel, string userAccessToken, Action<WineModel> callback)
        {
            Wine wine = Mapper.Map(wineModel);
            string encodedPhoto = Convert.ToBase64String(wineModel.Photo);

            string requestUrl = string.Format("{0}/Wines/Create", Globals.ServiceHostUrl);
            var request = new RestRequest(requestUrl, Method.PUT);
            request.AddBody(wine);
            request.AddParameter("createdByUserAccessToken", userAccessToken);
            request.AddParameter("photo", encodedPhoto);

            _restClient.ExecuteAsync<Wine>(request, (response) =>
            {
                Wine savedWine = response.Data;
                WineModel windeModel = Mapper.Map(savedWine);
                callback(windeModel);
            });
        }
コード例 #12
0
        public async Task UpdateWineById()
        {
            // Arrange
            var newWineModel = new WineModel
            {
                Name        = "Prosecco",
                RegionId    = 7,
                Sparkling   = true,
                Price       = 11.8M,
                Description = "White"
            };

            var addWineModel = await _wineService.AddNewWine(newWineModel);

            // Act
            var updWine = await _wineService.UpdateWineById(addWineModel);

            // Assert
            Assert.IsNotNull(updWine);
        }
コード例 #13
0
        public async Task AddWine()
        {
            // Arrange
            var newWineModel = new WineModel
            {
                Name        = "Valpolicella",
                RegionId    = 5,
                Sparkling   = false,
                Price       = 7.9M,
                Description = "Red"
            };

            // Act
            var output = await _wineService.AddNewWine(newWineModel);

            // Assert
            Assert.IsNotNull(output);
            Assert.AreEqual(output.Name, newWineModel.Name);
            Assert.IsTrue(output.ID > 0);
        }
コード例 #14
0
        public async Task GetAllWines()
        {
            // Arrange
            var newWineModel = new WineModel
            {
                Name        = "Marsala",
                RegionId    = 3,
                Sparkling   = false,
                Price       = 12.3M,
                Description = "White"
            };

            var addWineModel = await _wineService.AddNewWine(newWineModel);

            // Act
            var output = await _wineService.GetAllWines();

            // Assert
            Assert.IsNotNull(output);
            Assert.IsTrue(addWineModel.RegionId != 0);
            Assert.IsTrue(output.Count > 0);
        }
コード例 #15
0
        // add a new wine
        public async Task <WineModel> AddNewWine(WineModel newModel)
        {
            var addWine = _repository.Add <Wine.Data.Wine>(new Wine.Data.Wine
            {
                Name        = newModel.Name,
                RegionId    = newModel.RegionId,
                Price       = newModel.Price,
                Description = newModel.Description,
                Sparkling   = newModel.Sparkling
            });

            await _repository.CommitAsync();

            newModel.ID          = addWine.ID;
            newModel.Name        = addWine.Name;
            newModel.RegionId    = addWine.RegionId;
            newModel.Price       = addWine.Price;
            newModel.Description = addWine.Description;
            newModel.Sparkling   = addWine.Sparkling;

            return(newModel);
        }
コード例 #16
0
ファイル: WineController.cs プロジェクト: Beatrycze3/Liquors
        public IActionResult Index()
        {
            var alcohols = Context.Alcohols.Where(x => x.Wine != null).Include(x => x.Wine).ToList();
            var list     = new List <WineModel>();

            foreach (var item in alcohols)
            {
                var ratingList = Context.UserRates.Include(x => x.AlcoholVintage)
                                 .Where(x => x.AlcoholVintage.Alcohol == item).ToList();
                double rating = 0;

                if (ratingList.Count > 0)
                {
                    double sum = 0;

                    foreach (var rate in ratingList)
                    {
                        sum += rate.Rating;
                    }

                    rating = Convert.ToDouble(sum / ratingList.Count);
                }

                var wine = new WineModel()
                {
                    Id      = item.Id,
                    Country = item.Wine.Country,
                    Name    = item.Wine.Name,
                    Region  = item.Wine.Region,
                    Type    = item.Wine.Type,
                    Winery  = item.Wine.Winery,
                    Rating  = rating
                };

                list.Add(wine);
            }
            return(View(list));
        }
コード例 #17
0
ファイル: WineController.cs プロジェクト: Beatrycze3/Liquors
        public IActionResult Add(WineModel model)
        {
            if (ModelState.IsValid)
            {
                var wine = new Wine()
                {
                    Name    = model.Name,
                    Type    = model.Type,
                    Region  = model.Region,
                    Winery  = model.Winery,
                    Country = model.Country
                };
                var alcohol = new Alcohol()
                {
                    Wine = wine
                };

                Context.Alcohols.Add(alcohol);
                Context.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(model));
        }
コード例 #18
0
        public async Task GetWineById()
        {
            // Arrange
            var newWineModel = new WineModel
            {
                Name        = "Bordeaux",
                RegionId    = 1,
                Sparkling   = false,
                Price       = 5.6M,
                Description = "Red"
            };

            var addWine = await _wineService.AddNewWine(newWineModel);

            // Act

            var output = await _wineService.GetWineById(newWineModel.ID);

            // Assert
            Assert.IsNotNull(output);
            Assert.IsTrue(output.ID > 0);
            Assert.AreEqual(output.ID, newWineModel.ID);
        }
コード例 #19
0
        // get all
        public async Task <List <WineModel> > GetAllWines()
        {
            List <WineModel> allWines = new List <WineModel>();

            var getAll = _repository.All <Wine.Data.Wine>();

            foreach (Wine.Data.Wine wine in getAll)
            {
                var response = new WineModel()
                {
                    ID          = wine.ID,
                    Name        = wine.Name,
                    RegionId    = wine.RegionId,
                    Price       = wine.Price,
                    Description = wine.Description,
                    Sparkling   = wine.Sparkling
                };

                allWines.Add(response);
            }

            return(allWines);
        }
コード例 #20
0
        public async Task <IActionResult> AddWine([Bind("ID, Name, Description, Price, Sparkling, RegionId")] WineViewModel newEntry)
        {
            try
            {
                if (!ModelState.IsValid || newEntry == null)
                {
                    return(BadRequest());
                }

                var addWine = new WineModel
                {
                    Name        = newEntry.Name,
                    RegionId    = newEntry.RegionId,
                    Description = newEntry.Description,
                    Price       = newEntry.Price,
                    Sparkling   = newEntry.Sparkling
                };

                await _wineService.AddNewWine(addWine);

                var output = new WineViewModel
                {
                    ID          = addWine.ID,
                    Name        = addWine.Name,
                    RegionId    = addWine.RegionId,
                    Description = addWine.Description,
                    Price       = addWine.Price,
                    Sparkling   = addWine.Sparkling
                };
            }
            catch (WebException)
            {
                return(View());
            }

            return(RedirectToAction("Index", "wines"));
        }
コード例 #21
0
        public async Task <float> GetWinePrediction(WineModel model)
        {
            var prediction = await _client.PostJsonAsync <float>("/api/model", model);

            return(prediction);
        }