public AkcijaSpasavanje AddAction(AkcijaSpasavanje action, string identityName) { action.Vrijeme = DateTime.Now; action.FazaZivotnogCiklusa = (int)RescueCycleTypeEnum.Created; action.VoditeljId = _userRepository.GetUserByName(identityName).Id; _context.Add(action); Commit(); return(action); }
public IActionResult Save([FromBody] RescueActionDto dto) { var action = Mapper.Map <RescueActionDto, AkcijaSpasavanje>(dto); if (!ModelState.IsValid) { return(BadRequest(ErrorMessageCreator.GenerateErrorMessage(ErrorType.ValidationError, "Naziv, opis, potraga are required fields"))); } AkcijaSpasavanje actionNew = null; if (dto.Id != 0) { actionNew = _rescuersService.EditAction(dto, dto.Id); } else { actionNew = _rescuersService.AddAction(action, User.Identity.Name); } return(Ok(Mapper.Map <AkcijaSpasavanje, RescueActionDto>(actionNew))); }