Ejemplo n.º 1
0
        public IActionResult AddTDEvent([FromBody] Models.TDEventToManip tdEventToAdd)
        {
            _logger.Debug("Method to add new TDEvent was called");

            if (tdEventToAdd == null)
            {
                return(BadRequest());
            }
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var result = AutoMapper.Mapper.Map <Entities.TDEvent>(tdEventToAdd);

            try
            {
                _TDEventRep.AddTDEvent(result);
            }
            catch (Exception ex)
            {
                _logger.Error(ex, "Exception was throwed while addiction TDEvent: ");
            }

            if (!_TDEventRep.IsSaved())
            {
                _logger.Warn("TDList hasn`t been saved while addition TDEvent");
                return(StatusCode(500, "Server do not respond."));
            }

            _logger.Info("TDEvent has been successfully added: api/events/" + result.Id);
            return(CreatedAtRoute(result.Id, result));
        }
Ejemplo n.º 2
0
        public IActionResult UpdateTDEvent(int TDEventID, [FromBody] Models.TDEventToManip tdEventToPut)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var tdEvent = _TDEventRep.GetTDEvent(TDEventID);

            if (tdEvent == null)
            {
                return(NotFound());
            }
            AutoMapper.Mapper.Map(tdEventToPut, tdEvent);

            if (!_TDEventRep.IsSaved())
            {
                _logger.Warn("TDList hasn`t been saved while updating TDEvent");
                return(StatusCode(500, "Server do not respond"));
            }

            _logger.Info($"TDEvent with ID {TDEventID} has been successfully updated.");
            return(NoContent());
        }