public ActionResult <EditLocation> EditLocation(EditLocation model) { try { IMapper mapper = EDeliveryProfile.EditLocation(); var editedLocation = mapper.Map <Location>(model); var userIdClaim = User.FindFirst("MemberId")?.Value; var memberId = int.TryParse(userIdClaim, out var id) ? id : 0; EDeliveryDBContext dBContext = new EDeliveryDBContext(); var memberType = dBContext.Member.First(o => o.MemberId == memberId).MemberType; if (memberType.Equals(8)) { var customerId = dBContext.Customer.First(o => o.MemberId == memberId).CustomerId; editedLocation.CustomerId = customerId; } else if (memberType.Equals(9)) { var restaurantId = dBContext.Restaurant.First(o => o.MemberId == memberId).RestaurantId; editedLocation.RestaurantId = restaurantId; } else { return(BadRequest()); } _repository.EditLocation(editedLocation); return(new ObjectResult(new { message = "success", statusCode = HttpStatusCode.OK, response = "Succesfuly edited location" })); } catch (Exception ex) { _logger.LogError($"Failed to edit the location{ex}"); } return(BadRequest("Failed to edit the location")); }