コード例 #1
0
        public ActionResult <DeleteDriver> DeleteDriver([FromBody] DeleteDriver model)
        {
            try
            {
                IMapper mapper    = EDeliveryProfile.DeleteDriver();
                var     oldDriver = mapper.Map <Driver>(model);

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

                EDeliveryDBContext dBContext = new EDeliveryDBContext();
                var deliveryCompanyId        = dBContext.DeliveryCompany.First(o => o.MemberId == memberId).DeliveryCompanyId;
                oldDriver.DeliveryCompanyId = deliveryCompanyId;

                _repository.DeleteDriver(oldDriver);
                return(Ok()
                       );
            }
            catch (Exception ex)
            {
                _logger.LogError($"Failed to delete the driver{ex}");
            }

            return(BadRequest());
        }