public void ReturnReditectToPlaces_WhenModelStateIsValid()
        {
            // Arrange
            string            username     = "******";
            string            userId       = "some-id";
            string            redirectPage = "/places";
            AddPlaceViewModel viewModel    = new AddPlaceViewModel()
            {
                Address     = "address",
                Description = "description",
                CountryId   = 3
            };

            Place place = new Place()
            {
                Address     = "address",
                Description = "description",
                CountryId   = 3
            };

            this.mockedUserProvider.Setup(x => x.Username).Returns(username);
            this.mockedUserProvider.Setup(x => x.UserId).Returns(userId);

            this.mockedUserService.Setup(x => x.GetUserByUsername(username)).Returns(new User());

            this.mockedMappingService.Setup(x => x.Map <AddPlaceViewModel, Place>(viewModel)).Returns(place);

            // Act & Assert
            this.controller.WithCallTo(x => x.CreatePlace(viewModel))
            .ShouldRedirectTo(redirectPage);
        }
        public void CallPlacesServiceAddPlaceOnce()
        {
            // Arrange
            string            username  = "******";
            string            userId    = "some-id";
            AddPlaceViewModel viewModel = new AddPlaceViewModel()
            {
                Address     = "address",
                Description = "description",
                CountryId   = 3
            };

            Place place = new Place()
            {
                Address     = "address",
                Description = "description",
                CountryId   = 3
            };

            this.mockedUserProvider.Setup(x => x.Username).Returns(username);
            this.mockedUserProvider.Setup(x => x.UserId).Returns(userId);
            this.mockedUserService.Setup(x => x.GetUserByUsername(username)).Returns(new User());
            this.mockedMappingService.Setup(x => x.Map <AddPlaceViewModel, Place>(viewModel)).Returns(place);

            // Act
            this.controller.CreatePlace(viewModel);

            // Assert
            this.mockedPlacesService.Verify(x => x.AddPlace(It.IsAny <Place>()), Times.Once);
        }
Esempio n. 3
0
        public ActionResult CreatePlace()
        {
            AddPlaceViewModel model = new AddPlaceViewModel();

            model.Countries = this.GetAllCountries();

            return(this.View(model));
        }
Esempio n. 4
0
        public async Task AddNewPlace(AddPlaceViewModel placeModel)
        {
            var place = _mapper.Map <AddPlaceViewModel, Place>(placeModel);

            place.DateAdded    = _dateProvider.GetCurrentDateTime();
            place.ClientUserId = _userProvider.GetUserId();
            _context.Places.Add(place);
            await _context.SaveChangesAsync();
        }
        public async Task <IActionResult> Create([Bind("Name,Address1,City,County,Country,PostCode,Latitude,Longitude")] AddPlaceViewModel placeModel)
        {
            if (ModelState.IsValid)
            {
                await _placesService.AddNewPlace(placeModel);

                return(RedirectToAction("Index"));
            }

            return(View(placeModel));
        }
        public void ReturnDefaultView_WhenModelStateIsNotValid()
        {
            // Arrange
            AddPlaceViewModel viewModel = new AddPlaceViewModel()
            {
                Address = "address"
            };

            this.mockedCountryService.Setup(x => x.GetAllCountriesOrderedByName()).Returns(new List <Country>());
            this.controller.ModelState.AddModelError("test", "test-1");

            // Act & Assert
            this.controller.WithCallTo(x => x.CreatePlace(viewModel))
            .ShouldRenderDefaultView()
            .WithModel <AddPlaceViewModel>();
        }
Esempio n. 7
0
        public IActionResult Add(AddPlaceViewModel addPlaceViewModel)
        {
            if (ModelState.IsValid)
            {
                Place newCategory = new Place
                {
                    Name = addPlaceViewModel.Name
                };

                context.Places.Add(newCategory);
                context.SaveChanges();

                return(Redirect("/Place"));
            }

            return(View(addPlaceViewModel));
        }
Esempio n. 8
0
        public ActionResult AddPlace()
        {
            if (Session["userCode"] != null)
            {
                AddPlaceViewModel apvm = new AddPlaceViewModel();

                apvm.CountryList = new SelectList(entity.Countries, "CountryId", "CountryName");



                apvm.PlaceTypeList = new SelectList(entity.PlaceTypes, "PlaceTypeId", "PlaceTypeName");
                return(View(apvm));
            }
            else
            {
                Session["message"] = "please log in to do so.";
                return(RedirectToAction("Index", "Home"));
            }
        }
Esempio n. 9
0
        public ActionResult CreatePlace(AddPlaceViewModel model)
        {
            string userId   = this.userProvider.UserId;
            string username = this.userProvider.Username;

            model.FounderId   = userId;
            model.FounderName = username;

            if (!this.ModelState.IsValid)
            {
                model.Countries = this.GetAllCountries();
                return(this.View(model));
            }

            var user  = this.userService.GetUserByUsername(username);
            var place = this.mappingService.Map <AddPlaceViewModel, Place>(model);

            place.Founder = user;
            place.Country = this.countryService.GetCountryById(model.CountryId);

            this.placesService.AddPlace(place);

            return(this.Redirect(PlacesRedirect));
        }
Esempio n. 10
0
 public AddPlaceView()
 {
     InitializeComponent();
     BindingContext = new AddPlaceViewModel(this);
 }
Esempio n. 11
0
        public ActionResult AddPlace(AddPlaceViewModel apvm, HttpPostedFileBase AddPicture)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    int  countryId = Convert.ToInt32(apvm.CountryId);
                    int  cityId    = Convert.ToInt32(apvm.CityId);
                    bool result;
                    result = pl.CheckPlaceExist(apvm.PlaceName, countryId, cityId);
                    if (result == false)
                    {
                        int placeTypeId = Convert.ToInt32(apvm.PlaceTypeId);


                        Place place = new Place();
                        place.PlaceName   = apvm.PlaceName;
                        place.PlaceTypeId = Convert.ToInt32(apvm.PlaceTypeId);

                        place.CountryId    = Convert.ToInt32(apvm.CountryId);
                        place.CityId       = Convert.ToInt32(apvm.CityId);
                        place.PlaceAddress = apvm.PlaceAddress;
                        if (apvm.PlaceDetail == null)
                        {
                            place.PlaceDetail = "Not Given yet.";
                        }
                        else
                        {
                            place.PlaceDetail = apvm.PlaceDetail;
                        }

                        place.PlaceAdminsPermit          = true;
                        place.PlaceDateOfAccountCreation = DateTime.Now;
                        place.PlaceFavourite             = 0;
                        PlacePicture pp = new PlacePicture();
                        entity.Places.Add(place);

                        if (entity.SaveChanges() > 0)
                        {
                            var p = (from c in entity.Places where c.PlaceName == apvm.PlaceName && c.CountryId == apvm.CountryId && c.CityId == apvm.CityId select new { c.PlaceId, c.CountryId, c.CityId }).FirstOrDefault();
                            if (AddPicture != null)
                            {
                                PlaceAlbum pa = new PlaceAlbum();
                                pa.PlaceAlbumName           = "Profile Picture";
                                pa.PlaceId                  = p.PlaceId;
                                pa.AlbumTypeId              = 1;
                                pa.CityId                   = p.CityId;
                                pa.CountryId                = p.CountryId;
                                pa.PlaceAlbumAdminPermit    = true;
                                pa.PlaceAlbumPivacy         = true;
                                pa.PlaceAlbumDateOfCreation = DateTime.Now;
                                entity.PlaceAlbums.Add(pa);
                                entity.SaveChanges();
                                pp.PlacePictureData = new byte[AddPicture.ContentLength];
                                AddPicture.InputStream.Read(pp.PlacePictureData, 0, AddPicture.ContentLength);
                                pp.PlaceId = p.PlaceId;
                                var albumId = (from c in entity.PlaceAlbums where c.PlaceId == p.PlaceId && c.AlbumTypeId == 1 select c.PlaceAlbumId).Single();
                                int AlbumId = Convert.ToInt32(albumId);
                                pp.PlaceAlbumId            = AlbumId;
                                pp.AlbumTypeId             = 1;
                                pp.PlacePictureAdminPermit = true;
                                pp.CountryId = p.CountryId;
                                pp.CityId    = p.CityId;

                                pp.PlacePicturePrivacy     = true;
                                pp.PlacePictureDateOfAdded = DateTime.Now;
                                entity.PlacePictures.Add(pp);
                                if (entity.SaveChanges() > 0)
                                {
                                    Place d         = (from c in entity.Places where c.PlaceId == p.PlaceId select c).FirstOrDefault();
                                    int   pictureId = (from c in entity.PlacePictures
                                                       where c.PlaceId == p.PlaceId && c.AlbumTypeId == 1
                                                       orderby c.PlacePictureId descending
                                                       select c.PlacePictureId).First();
                                    d.PlaceProfilePicId = pictureId;
                                    entity.SaveChanges();
                                }
                            }
                            ModelState.Clear();
                            TempData["Success"] = "Added Successfully";
                        }
                        else
                        {
                            TempData["Success"] = "Problem occured";
                        }
                    }
                    else
                    {
                        TempData["Success"] = "Duplicacy found";
                    }
                    AddPlaceViewModel apvm1 = new AddPlaceViewModel();
                    apvm1.CountryList = new SelectList(entity.Countries, "CountryId", "CountryName");



                    apvm1.PlaceTypeList = new SelectList(entity.PlaceTypes, "PlaceTypeId", "PlaceTypeName");



                    return(View(apvm1));
                }
                catch (Exception ex)
                {
                    return(View("Error", new HandleErrorInfo(ex, "Place", "AddPlace")));
                }
            }
            else
            {
                AddPlaceViewModel apvm1 = new AddPlaceViewModel();
                apvm1.CountryList = new SelectList(entity.Countries, "CountryId", "CountryName");



                apvm1.PlaceTypeList = new SelectList(entity.PlaceTypes, "PlaceTypeId", "PlaceTypeName");



                return(View(apvm1));
            }
        }
 public AddPlace()
 {
     InitializeComponent();
     BindingContext = new AddPlaceViewModel(Navigation);
 }
Esempio n. 13
0
 public AddPlace()
 {
     InitializeComponent();
     DataContext = new AddPlaceViewModel(this);
 }
Esempio n. 14
0
        public IActionResult Add()
        {
            AddPlaceViewModel addPlaceViewModel = new AddPlaceViewModel();

            return(View(addPlaceViewModel));
        }