Beispiel #1
0
        public ActionResult <DeleteLocaiton> DeleteLocation([FromBody] DeleteLocaiton model)
        {
            try
            {
                IMapper mapper           = EDeliveryProfile.DeleteLocation();
                var     existingLocation = mapper.Map <Location>(model);

                var userIdClaim = User.FindFirst("MemberId")?.Value;
                var memberId    = int.TryParse(userIdClaim, out int id) ? id : 0;

                EDeliveryDBContext dBContext = new EDeliveryDBContext();

                var memberType = dBContext.Member.First(o => o.MemberId == memberId).MemberType;

                if (memberType.Equals(9))
                {
                    var restaurantId = dBContext.Restaurant.First(o => o.MemberId == memberId).RestaurantId;
                    existingLocation.RestaurantId = restaurantId;
                }
                else if (memberType.Equals(8))

                {
                    var customerId = dBContext.Customer.First(o => o.MemberId == memberId).CustomerId;
                    existingLocation.CustomerId = customerId;
                }
                else
                {
                    return(BadRequest());
                }

                _repository.DeleteLocation(existingLocation);
                return(Ok());
            }
            catch (Exception ex)
            {
                _logger.LogError($"Failed to delete the location:{ex}");
            }

            return(BadRequest());
        }