Exemplo n.º 1
0
        public async Task <IActionResult> GetAllBreweries()
        {
            var response = await _brewerySearchClient.GetBreweryInfo();

            var tempBreweryObj  = new Class1();
            var model           = new BreweryViewModel();
            var listOfBreweries = new List <Class1>();

            //foreach (Class1 brewery in response.Property1 )
            //{
            //    tempBreweryObj.name = brewery.name;
            //    tempBreweryObj.phone = brewery.phone;
            //    tempBreweryObj.street = brewery.street;
            //    tempBreweryObj.city = brewery.city;
            //    tempBreweryObj.state = brewery.state;
            //    tempBreweryObj.country = brewery.country;
            //    tempBreweryObj.postal_code = brewery.postal_code;
            //    tempBreweryObj.website_url = brewery.website_url;
            //    tempBreweryObj.brewery_type = brewery.brewery_type;

            //    listOfBreweries.Add(brewery);
            //}
            model.BreweriesList = response.Property1;
            return(View());
        }
Exemplo n.º 2
0
        public ActionResult Create(FormCollection collection, int id, int?userId = 1)
        {
            BreweryViewModel brewery = brewLogic.GetBrewery(id);
            UserViewModel    user    = new UserViewModel
            {
                Username = "******"
            };

            if (ModelState.IsValid)
            {
                try
                {
                    ReviewViewModel review = new ReviewViewModel
                    {
                        BreweryID         = id,
                        Rating            = Convert.ToInt32(collection["Rating"]),
                        ReviewDescription = collection["ReviewDescription"],
                        User    = user,
                        UserID  = (int)userId,
                        Brewery = brewery,
                    };
                    revLogic.PostReview(review);
                    return(RedirectToAction("Details", "Brewery", new { id = id }));
                }
                catch (Exception e)
                {
                    return(View("Caught Exception"));
                }
            }
            else
            {
                return(View("Invalid Model State"));
            }
        }
        private BreweryViewModel CreateBreweryFromForm(FormCollection formData)
        {
            BreweryViewModel result = new BreweryViewModel
            {
                BreweryID     = 1,
                Name          = formData["Name"],
                Description   = formData["Description"],
                ImageURL      = formData["ImageURL"],
                Address       = formData["Address"],
                ZipCode       = formData["ZipCode"],
                PhoneNumber   = formData["PhoneNumber"],
                BusinessHours = formData["BusinessHours"],
                HasTShirt     = Convert.ToBoolean(formData["HasTShirt"].Split(',')[0]),
                HasMug        = Convert.ToBoolean(formData["HasMug"].Split(',')[0]),
                HasGrowler    = Convert.ToBoolean(formData["HasGrowler"].Split(',')[0]),
                HasFood       = Convert.ToBoolean(formData["HasFood"].Split(',')[0]),
                AverageRating = 0,
                State         = new State
                {
                    StateID   = 10,
                    StateAbbr = "Fl"
                }
            };

            return(result);
        }
 static ReviewControllerTests()
 {
     collection = new FormCollection
     {
         { "ReviewDescription", "test" },
         { "Rating", "0" },
         { "ReviewID", "1" }
     };
     brewery = new BreweryViewModel
     {
         BreweryID     = 1,
         Name          = "test",
         Description   = "test",
         ImageURL      = "test.jpg",
         Address       = "test address",
         ZipCode       = "12345",
         PhoneNumber   = "555-555-5555",
         BusinessHours = "12PM-12AM",
         HasTShirt     = false,
         HasMug        = false,
         HasGrowler    = false,
         HasFood       = false,
         AverageRating = 0,
         State         = new State
         {
             StateID   = 10,
             StateAbbr = "Fl"
         }
     };
     user = new UserViewModel
     {
         Username = "******",
         UserID   = 1
     };
 }
Exemplo n.º 5
0
 public ActionResult Edit(int id, FormCollection collection) //The id parameter here refers to the REVIEW ID not the brewery Id
 {
     if (ModelState.IsValid)
     {
         try
         {
             ReviewViewModel review = new ReviewViewModel
             {
                 ReviewID          = id,
                 ReviewDescription = collection["ReviewDescription"],
                 Rating            = (float)Convert.ToDouble(collection["Rating"]),
                 UserID            = Convert.ToInt32(collection["UserID"]),
                 BreweryID         = Convert.ToInt32(collection["BreweryID"])
             };
             UserViewModel user = new UserViewModel
             {
                 Username = "******"
             };
             review.User = user;
             BreweryViewModel brewery = brewLogic.GetBrewery(review.BreweryID);
             review.Brewery = brewery;
             revLogic.PutReview(review);
             return(RedirectToAction("Details", "Brewery", new { id = brewery.BreweryID }));
         }
         catch (Exception)
         {
             return(View("Caught Exception"));
         }
     }
     else
     {
         return(View("Invalid Model State"));
     }
 }
Exemplo n.º 6
0
        public async Task <ActionResult> Index(string searchQuery = "",
                                               bool isAscending   = true,
                                               int pageNumber     = 1,
                                               string orderParam  = "")
        {
            ServiceParameter sp = new ServiceParameter
            {
                PageNumber  = pageNumber,
                SearchName  = searchQuery,
                OrderParam  = orderParam,
                IsAscending = isAscending
            };

            ServiceResponse <Brewery> response = await service.GetBreweries(sp);

            var    pagingSelectList = GetPageSelectList(response.TotalPage, response.CurrentPage);
            string requestUrl       = String.Format("/{0}/{1}", WebConfigurationManager.AppSettings["controllerName"],
                                                    WebConfigurationManager.AppSettings["actionName"]);

            BreweryViewModel <Brewery> result = new BreweryViewModel <Brewery>
            {
                PagingList  = pagingSelectList,
                SearchQuery = searchQuery,
                RequestUrl  = requestUrl,
                CurrentPage = response.CurrentPage,
                TotalPage   = response.TotalPage,
                Data        = response.Data
            };

            return(View(result));
        }
Exemplo n.º 7
0
        //POST: Brewery
        public ActionResult Details(int?id)
        {
            BreweryViewModel brewery = logic.GetBrewery((int)id);

            ViewBag.LogIn = CurrentUser.UserLoggedIn();
            return(View(brewery));
        }
Exemplo n.º 8
0
        public IActionResult Get(int id)
        {
            var breweryDTO = this._breweryServices.GetBrewery(id);
            var model      = new BreweryViewModel(breweryDTO);

            return(Ok(model));
        }
        public void HttpPutToApi <T>(T model, string apiString, int id)
        {
            BreweryViewModel brewery = model as BreweryViewModel;
            BreweryViewModel target  = list.Where(x => x.BreweryID == id).FirstOrDefault();

            if (target != null &&
                brewery.Name != null &&
                brewery.Address != null &&
                brewery.ZipCode != null)
            {
                target.Address       = brewery.Address;
                target.AverageRating = brewery.AverageRating;
                target.Beers         = brewery.Beers;
                target.BusinessHours = brewery.BusinessHours;
                target.Description   = brewery.Description;
                target.HasFood       = brewery.HasFood;
                target.HasGrowler    = brewery.HasGrowler;
                target.HasMug        = brewery.HasMug;
                target.HasTShirt     = brewery.HasTShirt;
                target.ImageURL      = brewery.ImageURL;
                target.Name          = brewery.Name;
                target.PhoneNumber   = brewery.PhoneNumber;
                target.Reviews       = brewery.Reviews;
                target.State         = brewery.State;
                target.ZipCode       = brewery.ZipCode;
            }
            else
            {
                throw new NonSuccessStatusCodeException("Non-success Status Code returned");
            }
        }
Exemplo n.º 10
0
        public ActionResult Edit(int id)
        {
            BreweryViewModel brewery = logic.GetBrewery(id);

            ViewBag.LogIn = CurrentUser.UserLoggedIn();
            return(View(brewery));
        }
Exemplo n.º 11
0
        // GET: Breweries/Create
        public async Task <IActionResult> Create()
        {
            var brewery   = new BreweryViewModel();
            var countries = await this.countryService.GetAllCountriesAsync();

            brewery.Countries = countries.Select(b => new SelectListItem(b.Name, b.Name)).ToList();

            return(View(brewery));
        }
Exemplo n.º 12
0
 public IActionResult Put(int id, [FromBody] BreweryViewModel breweryViewModel)
 {
     if (breweryViewModel == null)
     {
         return(BadRequest());
     }
     _breweryServices.UpdateBrewery(id, breweryViewModel.Name, breweryViewModel.Country);
     return(Ok(breweryViewModel));
 }
Exemplo n.º 13
0
        //
        // GET: /Admin/Brewery/Details/berweryidwer23r
        public ActionResult PartialDetails(string id)
        {
            var breweryViewModel = new BreweryViewModel()
            {
                Brewery = _breweryOrchestrator.GetById(id),
                Beers   = _beerOrchestrator.GetByBrewery(id)
            };

            return(PartialView("_BreweryDetails", breweryViewModel));
        }
Exemplo n.º 14
0
        public ActionResult Details(string id)
        {
            var brewery = new BreweryViewModel()
            {
                Brewery = _breweryOrchestrator.GetById(id),
                Beers   = _beerOrchestrator.GetByBrewery(id)
            };

            return(View("Details", brewery));
        }
Exemplo n.º 15
0
        public async Task <IActionResult> Put(int id, [FromBody] BreweryViewModel model)
        {
            if (id == 0 || model == null)
            {
                return(BadRequest());
            }
            var brewery = this.breweryService.UpdateBreweryAsync(id, model.Name, model.Description, model.CountryId);

            return(Ok());
        }
Exemplo n.º 16
0
        public async Task <IActionResult> Create(BreweryViewModel brewery)
        {
            if (ModelState.IsValid)
            {
                var dto = brewery.GetDTO();
                await this.breweryService.CreateBreweryAsync(dto);

                return(RedirectToAction(nameof(Index)));
            }
            return(View(brewery));
        }
Exemplo n.º 17
0
        public async Task <ActionResult> Brewery(string id)
        {
            var response = await _breweryService.GetBrewery(id);

            var model = new BreweryViewModel
            {
                Brewery = response.Brewery
            };

            return(View(model));
        }
        public void HttpDeleteFromApi(string apiString, int id)
        {
            BreweryViewModel target = list.Where(x => x.BreweryID == id).FirstOrDefault();

            if (target != null)
            {
                list.Remove(target);
            }
            else
            {
                throw new NonSuccessStatusCodeException("Non-success Status Code returned");
            }
        }
Exemplo n.º 19
0
        public async Task <IActionResult> Post([FromBody] BreweryViewModel model)
        {
            if (model == null)
            {
                return(BadRequest());
            }

            var breweryDTO = new BreweryDTO(model.Id, model.Name, model.Description, model.CountryId);


            var newBrewery = this.breweryService.CreateBreweryAsync(breweryDTO);

            return(Created("Post", newBrewery));
        }
        public void Delete_Test_ValidInput()
        {
            // Arrange
            BreweryViewModel brewery = CreateBreweryFromForm(collection);

            logic.PostBrewery(brewery);
            brewery = logic.GetBreweries().FirstOrDefault();

            // Act
            RedirectToRouteResult result = controller.Delete(brewery.BreweryID, collection) as RedirectToRouteResult;

            // Assert
            Assert.AreEqual("Breweries", result.RouteValues["action"]);
        }
        public void Details()
        {
            // Arrange
            BreweryViewModel brewery = CreateBreweryFromForm(collection);

            logic.PostBrewery(brewery);
            brewery = logic.GetBreweries().FirstOrDefault();

            // Act
            ViewResult result = controller.Details(brewery.BreweryID) as ViewResult;

            // Assert
            Assert.AreEqual(brewery.GetType(), result.Model.GetType());
        }
Exemplo n.º 22
0
        public async Task <IActionResult> Create([Bind("ID,Name,CountryID")] BreweryViewModel brewery)
        {
            if (ModelState.IsValid)
            {
                var newBrewery = await _service.CreateAsync(brewery.MapBreweryViewToDTO());

                //_context.Add(brewery);
                //await _context.SaveChangesAsync();
                brewery = newBrewery.MapBreweryDTOToView();
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CountryID"] = new SelectList(this._countryService.GetAllAsync().Result, "ID", "Name", brewery.Name);
            return(View(brewery));
        }
Exemplo n.º 23
0
        public async Task <IActionResult> Edit(int id, BreweryViewModel brewery)
        {
            if (id != brewery.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                await this.breweryService.UpdateBreweryAsync(id, brewery.Name);

                return(RedirectToAction(nameof(Index)));
            }
            return(View(brewery));
        }
Exemplo n.º 24
0
 public void PutBrewery(BreweryViewModel brewery)
 {
     try
     {
         api.HttpPutToApi <BreweryViewModel>(brewery, "breweries", brewery.BreweryID);
     }
     catch (NonSuccessStatusCodeException e)
     {
         Console.WriteLine($"Exception caught: {e}");
     }
     catch (Exception e)
     {
         Console.WriteLine($"Exception caught: {e}");
     }
 }
        public void HttpPostToApi <T>(T model, string apiString)
        {
            BreweryViewModel brewery = model as BreweryViewModel;

            if (brewery.Name != null &&
                brewery.Address != null &&
                brewery.ZipCode != null)
            {
                list.Add(model as BreweryViewModel);
            }
            else
            {
                throw new NonSuccessStatusCodeException("Non-success Status Code returned");
            }
        }
Exemplo n.º 26
0
 public static BreweryDTO GetDTO(this BreweryViewModel vm)
 {
     if (vm == null)
     {
         throw new ArgumentException();
     }
     ;
     return(new BreweryDTO
     {
         Id = vm.Id,
         Name = vm.Name,
         CountryId = vm.CountryId,
         Country = vm.Country,
         //Beers = vm.Beers.GetDTOs()
     });
 }
Exemplo n.º 27
0
        public async Task <IActionResult> Get(int id)
        {
            try
            {
                var breweryDTO = await this.breweryService.GetBreweryByIdAsync(id);

                var model = new BreweryViewModel(breweryDTO.Id, breweryDTO.Name,
                                                 breweryDTO.Description, breweryDTO.CountryId, breweryDTO.Country);

                return(Ok(model));
            }
            catch (Exception)
            {
                return(NotFound());
            }
        }
Exemplo n.º 28
0
        public static BreweryViewModel MapBreweryDTOToView(this BreweryDTO dto)
        {
            var breweryView = new BreweryViewModel()
            {
                ID        = dto.ID,
                Name      = dto.Name,
                CountryID = dto.CountryID,
                Country   = dto.Country,
                IsDeleted = dto.IsDeleted
            };

            if (dto.Beers != null)
            {
                breweryView.Beers = dto.Beers.Select(b => b.Name).ToList();
            }
            return(breweryView);
        }
        public async Task <IActionResult> Post([FromBody] BreweryViewModel model)
        {
            if (model == null)
            {
                return(BadRequest());
            }

            var breweryDTO = new BreweryDTO
            {
                Id      = model.Id,
                Name    = model.Name,
                Country = model.Country
            };
            var newBrewery = await this.breweryService.CreateBreweryAsync(breweryDTO);

            return(Created("Post", newBrewery));
        }
Exemplo n.º 30
0
        public async Task <ActionResult> GetBrewery(string name)
        {
            var response = await _breweryService.GetBreweries();

            var brewery = response.Breweries.FirstOrDefault(b => b.Name == name) ?? new Brewery
            {
                Name    = name,
                Address = new Address()
            };

            var model = new BreweryViewModel
            {
                Brewery = brewery
            };

            return(View("Brewery", model));
        }