public IHttpActionResult Get(int id)
 {
     var location = locationService.GetLocationById(id);
     var viewModel = new LocationViewModel();
     Mapper.Map(location, viewModel);
     return Ok(viewModel);
 }
 public IHttpActionResult Put(int id, LocationViewModel locationViewModel)
 {
     locationViewModel.Id = id;
     var location = locationService.GetLocationById(id);
     Mapper.Map(locationViewModel, location);
     locationService.UpdateLoaction(location);
     return Ok(locationViewModel);
 }
 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);
 }
        public IHttpActionResult Post(LocationViewModel location)
        {
            string userEmail = RequestContext.Principal.Identity.Name;
            var user = userManager.FindByName(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 Put(int id, LocationViewModel locationViewModel)
        {
            string userEmail = RequestContext.Principal.Identity.Name;
            var user = userManager.FindByName(userEmail);

            if (user != null)
            {
                locationViewModel.Id = id;
                var location = locationService.GetLocationById(id);
                Mapper.Map(locationViewModel, location);
                location.UserId = user.Id;
                locationService.UpdateLoaction(location);
                return Ok(locationViewModel);
            }
            return InternalServerError();
        }