Example #1
0
        public async void CreateLocation()
        {
            var newLocation = new LocationDto()
            {
                Name = "Practice Field"
            };

            var result = await _service.CreateLocation(newLocation);

            Assert.NotEqual(0, result);
        }
 public ActionResult Create(LocationCreate model)
 {
     if (ModelState.IsValid)
     {
         var service = new LocationService(Guid.Parse(User.Identity.GetUserId()));
         var result  = service.CreateLocation(model);
         TempData["SaveResult"] = "New location successfully created.";
         return(RedirectToAction("Index"));
     }
     return(View(model));
 }
 public EventLocation PostSave(EventLocation location)
 {
     if (location.Id > 0)
     {
         return(LocationService.UpdateLocation(location));
     }
     else
     {
         return(LocationService.CreateLocation(location, Security.GetUserId()));
     }
 }
Example #4
0
        public ActionResult Create(LocationCreate location)
        {
            if (ModelState.IsValid)
            {
                _userId          = Guid.Parse(User.Identity.GetUserId());
                _locationService = new LocationService(_userId);
                _locationService.CreateLocation(location);
                return(RedirectToAction("Index"));
            }

            return(View(location));
        }
        public Guid Create(string LocationTypeName)
        {
            //OLD
            //LocationType newLocType = new LocationType();
            //newLocType.Name = LocationTypeName;
            //Repositories.LocationTypeRepo.Insert(newLocType);

            //var Result = Repositories.LocationTypeRepo.GetByKey(newLocType.Key);
            var result = locationService.CreateLocation(LocationTypeName).Key;

            return(result);
        }
Example #6
0
        public IEnumerable <JsonLocation> TestPopulateSomeLocations()
        {
            string Msg = "";

            //TEST Add "Mindfly Office" location
            var locationService = new LocationService();
            var NewItem1Key     = locationService.CreateLocation("Mindfly Office", true);
            var NewItem1        = Repositories.LocationRepo.GetByKey(NewItem1Key);

            NewItem1.AddPropertyData(Constants.DefaultLocPropertyAlias.Address1, "114 W. Magnolia St");
            NewItem1.AddPropertyData(Constants.DefaultLocPropertyAlias.Address2, "Suite 300");
            NewItem1.AddPropertyData(Constants.DefaultLocPropertyAlias.Locality, "Bellingham");
            NewItem1.AddPropertyData(Constants.DefaultLocPropertyAlias.Region, "WA");
            NewItem1.AddPropertyData(Constants.DefaultLocPropertyAlias.PostalCode, "98225");
            NewItem1.AddPropertyData(Constants.DefaultLocPropertyAlias.CountryCode, "USA");
            NewItem1.AddPropertyData(Constants.DefaultLocPropertyAlias.Phone, "360-647-7470");
            NewItem1.AddPropertyData(Constants.DefaultLocPropertyAlias.Email, "*****@*****.**");
            locationService.UpdateLocation(NewItem1);

            Msg += string.Format("Location '{0}' added. ", NewItem1.Name);

            //TEST Add "Heather's House" location
            var NewItem2Key = locationService.CreateLocation("Heather's House", true);
            var NewItem2    = Repositories.LocationRepo.GetByKey(NewItem2Key);

            NewItem2.AddPropertyData(Constants.DefaultLocPropertyAlias.Address1, "1820 Madison Avenue");
            NewItem2.AddPropertyData(Constants.DefaultLocPropertyAlias.Address2, "8C");
            NewItem2.AddPropertyData(Constants.DefaultLocPropertyAlias.Locality, "New York");
            NewItem2.AddPropertyData(Constants.DefaultLocPropertyAlias.Region, "NY");
            NewItem2.AddPropertyData(Constants.DefaultLocPropertyAlias.PostalCode, "10035");
            NewItem2.AddPropertyData(Constants.DefaultLocPropertyAlias.CountryCode, "USA");
            locationService.UpdateLocation(NewItem2);

            Msg += string.Format("Location '{0}' added. ", NewItem2.Name);

            //TEST: Return all Location Types
            var Result = Repositories.LocationRepo.ConvertToJsonLocations(Repositories.LocationRepo.GetAll());

            return(Result);
        }
        public IActionResult Create(CreateLocationModel model)
        {
            var validationResult = _service.ValidateCreateLocation(User, model);

            if (!validationResult.Valid)
            {
                return(BadRequest(validationResult.Result));
            }
            var entity = _service.CreateLocation(model);

            context.SaveChanges();
            return(Created($"/{ApiEndpoint.LOCATION_API}?id={entity.Id}",
                           new AppResultBuilder().Success(entity.Id)));
        }
Example #8
0
        public async void CanCreateLocation()
        {
            DbContextOptions <GameDbContext> options = new DbContextOptionsBuilder <GameDbContext>().UseInMemoryDatabase("text").Options;

            using (GameDbContext context = new GameDbContext(options))
            {
                LocationService locationService = new LocationService(context);
                Location        location        = new Location();
                await locationService.CreateLocation(location);

                var actual = await context.Locations.FirstOrDefaultAsync(l => l.ID == location.ID);

                Assert.Equal(location, actual);
            }
        }
Example #9
0
        public IHttpActionResult Post(LocationCreate location)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }


            if (!_locationService.CreateLocation(location))
            {
                return(InternalServerError());
            }

            return(Ok("The location was successfully created"));
        }
        public IHttpActionResult PostLocation([FromBody] LocationCreate location)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var service = new LocationService();

            if (!service.CreateLocation(location))
            {
                return(InternalServerError());
            }

            return(Ok("Location successfully added."));
        }
Example #11
0
        public async void CanGetLocations()
        {
            DbContextOptions <GameDbContext> options = new DbContextOptionsBuilder <GameDbContext>().UseInMemoryDatabase("text").Options;

            using (GameDbContext context = new GameDbContext(options))
            {
                LocationService locationService = new LocationService(context);
                Location        location        = new Location();
                await locationService.CreateLocation(location);

                var expected = await context.Locations.ToListAsync();

                var actual = await locationService.GetLocations();

                Assert.Equal(expected, actual);
            }
        }
Example #12
0
        public ActionResult Create(LocationCreate model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var service = new LocationService();

            if (service.CreateLocation(model))
            {
                TempData["SaveResult"] = "Location was created.";
                return(RedirectToAction("Index"));
            }
            ModelState.AddModelError("", "Location could not be created.");
            return(View(model));
        }
Example #13
0
        public async Task <IActionResult> Create([Bind("Id,DivisionId,Name,Details")] Location location)
        {
            if (ModelState.IsValid)
            {
                var result = await _service.CreateLocation(location);

                if (result == 1)
                {
                    return(RedirectToAction(nameof(Index)));
                }
                else
                {
                    return(NotFound());
                }
            }
            ViewData["DivisionId"] = new SelectList(_context.Divisions, "Id", "Name", location.DivisionId);
            return(View(location));
        }
        public async Task <HttpResponseMessage> CreateLocation([FromBody] LocationDto location)
        {
            HttpResponseMessage result;

            try
            {
                await LocationService.CreateLocation(location);

                result = Request.CreateResponse(HttpStatusCode.Created);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                result = Request.CreateErrorResponse(HttpStatusCode.InternalServerError, e.Message);
            }

            return(result);
        }
Example #15
0
        public async Task <IActionResult> CreateLocation([FromBody, Required] LocationDto locationDto)
        {
            try
            {
                if (locationDto == null)
                {
                    return(BadRequest());
                }

                var result = await _service.CreateLocation(locationDto);

                return(CreatedAtRoute("default", result));
            }
            catch (Exception ex)
            {
                Log.Error(ex, ex.Message);
                return(BadRequest(ex.Message));
            }
        }
Example #16
0
 public Guid Create(string locationName)
 {
     return(locationService.CreateLocation(locationName).Key);
 }
Example #17
0
        public IEnumerable<JsonLocation> TestPopulateSomeLocations()
        {
            string Msg = "";

            //TEST Add "Mindfly Office" location
            var locationService = new LocationService();
            var NewItem1Key = locationService.CreateLocation("Mindfly Office", true);
            var NewItem1 = Repositories.LocationRepo.GetByKey(NewItem1Key);
            NewItem1.AddPropertyData(Constants.DefaultLocPropertyAlias.Address1, "114 W. Magnolia St");
            NewItem1.AddPropertyData(Constants.DefaultLocPropertyAlias.Address2, "Suite 300");
            NewItem1.AddPropertyData(Constants.DefaultLocPropertyAlias.Locality, "Bellingham");
            NewItem1.AddPropertyData(Constants.DefaultLocPropertyAlias.Region, "WA");
            NewItem1.AddPropertyData(Constants.DefaultLocPropertyAlias.PostalCode, "98225");
            NewItem1.AddPropertyData(Constants.DefaultLocPropertyAlias.CountryCode, "USA");
            NewItem1.AddPropertyData(Constants.DefaultLocPropertyAlias.Phone, "360-647-7470");
            NewItem1.AddPropertyData(Constants.DefaultLocPropertyAlias.Email, "*****@*****.**");
            locationService.UpdateLocation(NewItem1);

            Msg += string.Format("Location '{0}' added. ", NewItem1.Name);

            //TEST Add "Heather's House" location
            var NewItem2Key = locationService.CreateLocation("Heather's House", true);
            var NewItem2 = Repositories.LocationRepo.GetByKey(NewItem2Key);
            NewItem2.AddPropertyData(Constants.DefaultLocPropertyAlias.Address1, "1820 Madison Avenue");
            NewItem2.AddPropertyData(Constants.DefaultLocPropertyAlias.Address2, "8C");
            NewItem2.AddPropertyData(Constants.DefaultLocPropertyAlias.Locality, "New York");
            NewItem2.AddPropertyData(Constants.DefaultLocPropertyAlias.Region, "NY");
            NewItem2.AddPropertyData(Constants.DefaultLocPropertyAlias.PostalCode, "10035");
            NewItem2.AddPropertyData(Constants.DefaultLocPropertyAlias.CountryCode, "USA");
            locationService.UpdateLocation(NewItem2);

            Msg += string.Format("Location '{0}' added. ", NewItem2.Name);

            //TEST: Return all Location Types
            var Result = Repositories.LocationRepo.ConvertToJsonLocations(Repositories.LocationRepo.GetAll());

            return Result;
        }
        public Guid Create(string locationName)
        {
            var locationService = new LocationService();

            return(locationService.CreateLocation(locationName));
        }
 public Guid Create(string locationName, Guid locationTypeGuid)
 {
     var locationService = new LocationService();
     return locationService.CreateLocation(locationName, locationTypeGuid);
 }
 public Guid Create(string locationName)
 {
     var locationService = new LocationService();
     return locationService.CreateLocation(locationName);
 }
        public Guid Create(string locationName, Guid locationTypeGuid)
        {
            var locationService = new LocationService();

            return(locationService.CreateLocation(locationName, locationTypeGuid));
        }