Exemple #1
0
        public void AddLocation_Should_AddLocation()
        {
            // Arrange
            var loc = getLocation();

            // Act
            var result = service.AddLocation(loc);

            // Assert
            Assert.IsTrue(result.IsOK);
            Assert.IsNotNull(service.GetLocation(99));
            Assert.AreEqual(service.GetLocation(99).Name, "New York");
        }
        public ActionResult <ItemResponse <int> > CreateLocation(LocationAddRequest model)
        {
            ObjectResult result = null;

            try
            {
                int userId = _authService.GetCurrentUserId();

                int id = _lService.AddLocation(model, userId);

                ItemResponse <int> response = new ItemResponse <int>()
                {
                    Item = id
                };
                result = Created201(response);
            }
            catch (Exception e)
            {
                Logger.LogError(e.ToString());
                ErrorResponse response = new ErrorResponse(e.Message);

                result = StatusCode(500, response);
            }

            return(result);
        }
Exemple #3
0
        public IActionResult EditLocationModal(EditLocation model)
        {
            if (ModelState.IsValid)
            {
                LocationDto dto = new LocationDto()
                {
                    Address      = model.Address,
                    City         = model.City,
                    Country      = model.Country,
                    Description  = model.Description,
                    LocationId   = model.LocationId,
                    LocationName = model.LocationName,
                    StateRegion  = model.StateRegion,
                    ZipCode      = model.ZipCode
                };

                if (model.IsAddNew)
                {
                    model.Result = LocationService.AddLocation(dto);
                }
                else
                {
                    model.Result = LocationService.UpdateLocation(dto);
                }
            }

            return(PartialView("_EditLocationPartial", model));
        }
Exemple #4
0
        public async Task Add(string locationName, string faction, int level)
        {
            try
            {
                var deleteResult = await _locationService.AddLocation(locationName, faction, level);

                switch (deleteResult)
                {
                case LocationCreationResult.OK:
                    await Context.AddConfirmation();

                    break;

                case LocationCreationResult.Duplicate:
                    await Context.AddRejection();
                    await ReplyAsync($"Duplicate system");

                    break;

                case LocationCreationResult.CantFindSystem:
                    await Context.AddRejection();
                    await ReplyAsync($"Could not find system");

                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex, "Failed adding system");
            }
        }
Exemple #5
0
        public ActionResult CreateEdit(ULocation location, string Action = "")
        {
            if (ModelState.IsValid)
            {
                if (Action.Equals("Edit"))
                {
                    location._Location.CountryProgrammeId = countryProg.Id;
                    if (locationService.EditLocation(location._Location))
                    {
                        ModelState.Clear();
                        location = new ULocation();
                    }
                }
                else
                {
                    location._Location.CountryProgrammeId = countryProg.Id;
                    if (locationService.AddLocation(location._Location))
                    {
                        ModelState.Clear();
                        location = new ULocation();
                    }
                }
            }

            return(ListView());
        }
        public void AddRemoveLocationTest()
        {
            LocationDto dto = new LocationDto()
            {
                LocationId       = TestLocationId,
                LocationName     = TEST_LOCATION_NAME,
                Description      = TEST_DESCRIPTION,
                Address          = TEST_ADDRESS,
                City             = TEST_CITY,
                StateRegion      = TEST_STATE,
                ZipCode          = TEST_ZIP,
                Country          = TEST_COUNTRY,
                CreateUserId     = TestUserId,
                LastUpdateUserId = TestUserId
            };

            var addResult = Service.AddLocation(dto);

            Assert.IsTrue(addResult.IsSuccess);

            var loc = Service.GetLocation(dto.LocationId);

            Assert.IsNotNull(loc);
            Assert.AreEqual(TestLocationId, loc.LocationId);
            Assert.AreEqual(TEST_LOCATION_NAME, loc.LocationName);
            Assert.AreEqual(TEST_DESCRIPTION, loc.Description);
            Assert.AreEqual(TEST_ADDRESS, loc.Address);
            Assert.AreEqual(TEST_CITY, loc.City);
            Assert.AreEqual(TEST_STATE, loc.StateRegion);
            Assert.AreEqual(TEST_ZIP, loc.ZipCode);
            Assert.AreEqual(TEST_COUNTRY, loc.Country);
            Assert.AreEqual(TestUserId, loc.CreateUserId);
            Assert.AreEqual(TestUserId, loc.LastUpdateUserId);

            dto.Description = TEST_DESCRIPTION_2;
            var updateResult = Service.UpdateLocation(dto);

            Assert.IsTrue(updateResult.IsSuccess);

            loc = Service.GetLocation(dto.LocationId);
            Assert.IsNotNull(loc);
            Assert.AreEqual(TEST_DESCRIPTION_2, loc.Description);

            var deleteResult = Service.DeleteLocation(dto.LocationId);

            Assert.IsTrue(deleteResult.IsSuccess);
        }
Exemple #7
0
        public async Task <Object> NewDeliveryMan([FromBody] UserForCreationDto newDeliveryMan)
        {
            var identityUser = new IdentityUser
            {
                Email    = newDeliveryMan.Email,
                UserName = newDeliveryMan.Email
            };

            if (await _userManager.FindByEmailAsync(newDeliveryMan.Email) != null)
            {
                return(BadRequest(new { code = "DuplicatedEmail", message = "Cette adresse email est déjà utilisée." }));
            }

            try
            {
                var result = await _userManager.CreateAsync(identityUser, newDeliveryMan.Password);

                if (result.Succeeded)
                {
                    IdentityUser user = _userManager.Users.Where(u => u.Email == newDeliveryMan.Email).FirstOrDefault();


                    //Insert in the table location
                    var location = locationService.AddLocation(newDeliveryMan.Location);

                    //Transform the image base64 String
                    ImageModel uploadedImage = FileUploader.Base64ToImage(newDeliveryMan.ImageBase64String, "DeliveryMenPictures");

                    //Create the client entity
                    var entityDeliveryMan = new DeliveryMan
                    {
                        IdentityId        = user.Id,
                        Email             = newDeliveryMan.Email,
                        FirstName         = newDeliveryMan.FirstName,
                        LastName          = newDeliveryMan.LastName,
                        Phone             = newDeliveryMan.Phone,
                        DateOfBirth       = newDeliveryMan.DateOfBirth,
                        ImageBase64       = uploadedImage.ImageBytes,
                        PicturePath       = uploadedImage.Path,
                        Location          = location,
                        HasValidatedEmail = false,
                        IsValidated       = false
                    };

                    //Insert the new user in the DB
                    var addedDeliveryMan = deliveryMenService.AddDeliveryMan(entityDeliveryMan);

                    //Send the verification email
                    var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                    SendVerificationEmail(addedDeliveryMan, user.Id, code);
                }
                return(Ok(result));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public async Task <IActionResult> AddLocation([FromBody] LocationDto newLocation)
        {
            _logger.LogInformation($"Adding new location, {newLocation.Name}");

            var result = await _locationService.AddLocation(newLocation);

            return(Ok(result));
        }
 public ActionResult Add(Location location)
 {
     if (ModelState.IsValid)
     {
         var status = _locationService.AddLocation(location) ? "Saved Successfully!" : "Could not Save!";
         return(Json(status));
     }
     return(View(location));
 }
 public IActionResult AddEvent([FromBody] AddLocationDto locationDto)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest());
     }
     _locationServices.AddLocation(locationDto);
     return(Ok());
 }
Exemple #11
0
        public ActionResult Add(Location location)
        {
            if (ModelState.IsValid)
            {
                var result = _locationService.AddLocation(location);
                ViewBag.HasSaved = result;
            }

            return(View(location));
        }
Exemple #12
0
        //[Authorize(Roles = "Admin")]
        public IHttpActionResult Post(LocationViewModel location)
        {
            Location entity = new Location();

            Mapper.Map(location, entity);
            entity.CreatedOn = DateTime.UtcNow;
            locationService.AddLocation(entity);
            Mapper.Map(entity, location);
            return(Created(Url.Link("DefaultApi", new { controller = "Locations", id = location.Id }), location));
        }
Exemple #13
0
        public LocationDto SeedLocation()
        {
            LocationDto dto = new LocationDto()
            {
                LocationId   = Guid.NewGuid(),
                LocationName = "Test Location 2"
            };

            Location.AddLocation(dto);
            return(dto);
        }
Exemple #14
0
 public IActionResult AddLocation(Location location)
 {
     try
     {
         _locationService.AddLocation(location);
         return(CreatedAtAction("AddLocation", location));
     }
     catch (Exception)
     {
         return(BadRequest());
     }
 }
 public IActionResult AddLocation(LocationResource location)
 {
     try
     {
         _locationService.AddLocation(_mapper.ParseLocation(location));
         _locationService.SaveChanges();
         return(CreatedAtAction("AddLocation", location));
     }
     catch (Exception)
     {
         return(BadRequest());
     }
 }
        public ActionResult AddNewLocation4OR(ULocation model, bool final, Guid?otherDDSelectedId)
        {
            Location location = locationService.GetLocationByName(model.Name, countryProg.Id);

            if (location == null)
            {
                location                    = new Location();
                location.Name               = model.Name;
                location.Description        = model.Description;
                location.CountryId          = model.CountryId;
                location.CountryProgrammeId = countryProg.Id;
                locationService.AddLocation(location);
            }
            return(RepopulateLocationLists(location.Id, final, otherDDSelectedId));
        }
Exemple #17
0
        public static void AddLocationsToDatabase()
        {
            tblLOCATION   location  = new tblLOCATION();
            List <string> locations = ReadLocationsFromFile();

            foreach (var l in locations)
            {
                string[] locationData = l.Split(',');

                location.Adress  = locationData[0];
                location.Place   = locationData[1];
                location.Country = locationData[2];

                service.AddLocation(location);
            }
        }
        public async Task <ActionResult <LocationDTO> > Post([FromBody] LocationDTO location)
        {
            var userId = Int32.Parse(User.Claims.FirstOrDefault(x => x.Type.Equals("UserId")).Value);

            location.UserId = userId;
            var result = await locationsService.AddLocation(location);

            if (result != null)
            {
                return(Created("Tu imagen fue registrada.", result));
            }
            else
            {
                return(Conflict("Ha ocurrido un error guardando su imagen"));
            }
        }
Exemple #19
0
        public ActionResult AddNewLocation4PO(ULocation model)
        {
            Location location = null;

            location = locationService.GetLocationByName(model.Name, countryProg.Id);
            if (location == null)
            {
                location                    = new Location();
                location.Name               = model.Name;
                location.Description        = model.Description;
                location.CountryId          = model.CountryId;
                location.CountryProgrammeId = countryProg.Id;
                //location.IsApproved = false;
                locationService.AddLocation(location);
            }
            return(RepopulateLocationList(location.Id));
        }
        public static void AddLocationsToDatabase()
        {
            tblLocation   location  = new tblLocation();
            List <string> locations = ReadLocationsFromFile();

            foreach (var l in locations)
            {
                string[] locationData = l.Split(',');

                location.Street  = locationData[0];
                location.Number  = locationData[1];
                location.City    = locationData[2];
                location.Country = locationData[3];

                service.AddLocation(location);
            }
        }
Exemple #21
0
        public IHttpActionResult Post(LocationViewModel location)
        {
            string userEmail = Thread.CurrentPrincipal.Identity.Name;
            var    user      = userService.GetUserByEmail(userEmail);

            if (user != null)
            {
                Location entity = new Location();
                Mapper.Map(location, entity);
                entity.CreatedOn = DateTime.UtcNow;
                entity.UserId    = user.Id;
                locationService.AddLocation(entity);
                Mapper.Map(entity, location);
                return(Created(Url.Link("DefaultApi", new { controller = "Locations", id = location.Id }), location));
            }
            return(InternalServerError());
        }
        public IHttpActionResult Post(CreateLocationViewModel createModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var locationData = new Location();

            AutoMapper.Mapper.Map(createModel, locationData);
            _locationService.AddLocation(locationData);

            var locationViewModel = new LocationViewModel();

            AutoMapper.Mapper.Map(locationData, locationViewModel);

            return(Created(new Uri(Request.RequestUri + "api/loctions" + locationViewModel.Id), locationViewModel));
        }
        public async Task <ActionResult <Location> > PostLocation(Location location)
        {
            try
            {
                await _locationService.AddLocation(location);
            }
            catch (LocationIdAlreadyExistsException e)
            {
                return(Conflict(e));
            }
            catch (LocationNameAlreadyExistsException e)
            {
                return(Conflict(e));
            }
            catch (DbUpdateException)
            {
                throw;
            }

            return(CreatedAtAction("GetLocation", new { id = location.LocationId }, location));
        }
        public IActionResult AddLocation([FromBody] LocationDto location)
        {
            Result result = locationService.AddLocation(location);

            if (result.Success)
            {
                return(Ok());
            }
            else
            {
                if (result.Exception != null)
                {
                    Log.Error(result.Exception, "Error adding location to database!");
                    return(StatusCode(500));
                }
                else
                {
                    Log.Warning("Unable to add location to database!");
                    return(Conflict());
                }
            }
        }
Exemple #25
0
 public ActionResult AddLocation(ULocation model)
 {
     locationService.AddLocation(model._Location);
     return(Details(model._Location.CountryProgrammeId));
 }
        public IActionResult AddLocation(AddLocationRequest request)
        {
            _locationService.AddLocation(request, Account);

            return(Created());
        }
Exemple #27
0
 public void Post([FromBody] Location value)
 {
     _service.AddLocation(value);
 }
Exemple #28
0
        public ActionResult SaveLocation([FromBody] Location request)
        {
            var result = _locationService.AddLocation(null);

            return(new JsonResult(result));
        }
 public Location AddLocation(Location location)
 {
     return(locationService.AddLocation(location));
 }
 public async Task <IActionResult> Add(AddLocationDTO l)
 {
     return(Ok(await _locationService.AddLocation(l)));
 }