Exemplo n.º 1
0
        public ActionResult <EditDriver> EditDriver(EditDriver model)
        {
            try
            {
                IMapper mapper = EDeliveryProfile.EditDriver();
                var     result = 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;
                result.DeliveryCompanyId = deliveryCompanyId;

                _repository.EditDriver(result);

                return(new ObjectResult(new { message = "success", statusCode = HttpStatusCode.OK, response = "Succesfuly edited driver" }));
            }
            catch (Exception ex)
            {
                _logger.LogError($"Failed to edit the driver{ex}");
            }

            return(BadRequest("Failed to edit the driver"));
        }