Esempio n. 1
0
        public async Task <JsonResult> CreatePlace([FromBody] CreatePlace model)
        {
            try
            {
                IMongoCollection <InsertPlace> places = _database.GetCollection <InsertPlace>("places");

                var myNewPlace = new InsertPlace()
                {
                    Name         = model.Name,
                    Description  = model.Description,
                    Website      = model.Website,
                    OpeningHours = model.OpeningHours,
                    Type         = model.Type,
                    Address      = model.Address,
                    Email        = model.Email,
                    CountryId    = new ObjectId(model.CountryId),
                    Location     = new GeoLoc(model.Latitude, model.Longitude),
                    PhoneNumber  = model.PhoneNumber
                };
                await places.InsertOneAsync(myNewPlace);

                return(Json(new { result = true }.ToJson(jsonWriterSettings)));
            }
            catch (Exception ex)
            {
                return(Json(ex.RaiseException()));
            }
        }
Esempio n. 2
0
        public IActionResult Create([FromBody] CreatePlaceInput place)
        {
            var result = new CreatePlace(Repository, place).Execute();

            if (result == -1)
            {
                return(Conflict());
            }
            return(Ok(result));
        }
Esempio n. 3
0
        public void ShouldFailCreatingPlace()
        {
            var place         = new CreatePlaceInput("test", true, true, true, 1, 2, 3);
            var mockPlaceRepo = new Mock <IPlaceRepository>();

            mockPlaceRepo.Setup(m => m.Create(It.IsAny <domain.Place>())).Returns(-1);
            var res = new CreatePlace(mockPlaceRepo.Object, place).Execute();

            Assert.AreEqual(-1, res);
        }