示例#1
0
        public bool Update(DatePlanningForUpdateDto datePlanningForUpdate)
        {
            try
            {
                var datePlanningDto = GetById(datePlanningForUpdate.id);

                if (datePlanningDto == null)
                {
                    return(false);
                }

                DatePlanning DataEntity = _mapper.Map <DatePlanning>(datePlanningDto);

                _mapper.Map(datePlanningForUpdate, DataEntity);

                _repository.Update(DataEntity);
                _repository.Save();

                _logger.LogError($"Updated DatePlanning with id: {DataEntity.id}");

                return(true);
            }
            catch (Exception ex)
            {
                _logger.LogError($"Something went wrong inside UpdateDatePlanning action: {ex.Message}");
                throw new Exception();
            }
        }
        public IActionResult UpdateDatePlanning([FromBody] DatePlanningForUpdateDto datePlanning)
        {
            try
            {
                if (datePlanning == null)
                {
                    _logger.LogError("date planning object sent from client is null.");
                    return(BadRequest("date planning object is null"));
                }

                if (!ModelState.IsValid)
                {
                    _logger.LogError("Invalid date planning object sent from client.");
                    return(BadRequest("Invalid model object"));
                }

                bool succes = _datePlanningLogic.Update(datePlanning);

                if (!succes)
                {
                    return(NotFound());
                }

                return(Ok("date planning is updated"));
            }
            catch (Exception ex)
            {
                return(StatusCode(500, "Internal server error"));
            }
        }