Ejemplo n.º 1
0
        public async Task <IActionResult> AddLocation(LocationDto model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Something want wrong while adding location"));
            }

            var location = new Location
            {
                ZipCode       = model.ZipCode,
                City          = model.City,
                Country       = model.Country,
                StreetAddress = model.StreetAddress
            };

            await _locationService.AddLocationAsync(location);

            await _genericRepository.SaveChangesAsync();

            return(Ok(new
            {
                status = 200,
                message = "Location Added successfully!"
            }));
        }
Ejemplo n.º 2
0
        public async Task <ActionResult> AddLocation([FromBody] LocationCreateBindingModel locationInfo)
        {
            if (locationInfo == null && !ModelState.IsValid)
            {
                return(BadRequest(GlobalConstants.ErrorLocationIsInValid));
            }

            var location = Mapper.Map <MrsMobileLocation>(locationInfo);

            var userId = this.User.FindFirst(ClaimTypes.NameIdentifier).Value;

            location.UserId = userId;

            await locationService.AddLocationAsync(location);

            return(StatusCode(201));
        }
Ejemplo n.º 3
0
        public async Task <ActionResult <Location> > Post(int accountId, [FromBody] Location newLocation)
        {
            try
            {
                Guard.AgainstAccountNumberMismatch(GetAccountIdClaim(), accountId.ToString(), "userClaim.accountId", "accountId");
                var result = await locationService.AddLocationAsync(accountId, newLocation);

                return(Ok(result));
            }
            catch (AccountConflictException)
            {
                return(Forbid());
            }
            catch (Exception)
            {
                return(BadRequest("Error adding location"));
            }
        }
Ejemplo n.º 4
0
 public async Task <int> Post(Location location)
 {
     return(await _locationService.AddLocationAsync(location));
 }