public IActionResult CreateInstitution(InstitutionResource institutionResource) { if (institutionResource == null) { ProblemDetails problem = new ProblemDetails { Title = "Failed creating the institution.", Detail = "The institution resource is null.", Instance = "E80F9611-EE07-4FF0-8D53-7693CE1AE26E" }; return(BadRequest(problem)); } Institution institution = mapper.Map <InstitutionResource, Institution>(institutionResource); try { institutionService.Add(institution); institutionService.Save(); InstitutionResourceResult model = mapper.Map <Institution, InstitutionResourceResult>(institution); return(Created(nameof(CreateInstitution), model)); } catch (DbUpdateException e) { Log.Logger.Error(e, "Database exception"); ProblemDetails problem = new ProblemDetails { Title = "Failed Saving the institution.", Detail = "Failed saving the institution to the database.", Instance = "20C197B7-24E1-4112-8999-6BB3DFD03FB6" }; return(BadRequest(problem)); } }
public InstitutionViewModel Add(InstitutionViewModel institutionViewModel) { var institution = _mapper.Map <InstitutionViewModel, Institution>(institutionViewModel); _uow.BeginTransaction(); var institutionReturn = _institutionService.Add(institution); _uow.Commit(); institutionViewModel = _mapper.Map <Institution, InstitutionViewModel>(institutionReturn); return(institutionViewModel); }
public async Task <IActionResult> AddEdit(Institution model) { if (!ModelState.IsValid) { return(View(model)); } if (model.Id == 0) { await _institutionService.Add(model); } else { await _institutionService.Edit(model); } return(RedirectToAction("List", "Institution")); }
public InstitutionDTO Save(InstitutionDTO entityDTO) { var mapper = new MapperConfiguration(cfg => { cfg.CreateMap <InstitutionDTO, Institution>(); }).CreateMapper(); Institution result = string.IsNullOrEmpty(entityDTO.Id) ? new Institution() : instService.GetById(entityDTO.Id); mapper.Map <InstitutionDTO, Institution>(entityDTO, result); if (string.IsNullOrEmpty(entityDTO.Id)) { result.Id = Guid.NewGuid().ToString(); instService.Add(result); } instService.Save(); mapper = new MapperConfiguration(cfg => { cfg.CreateMap <Institution, InstitutionDTO>(); }).CreateMapper(); return(mapper.Map <InstitutionDTO>(result)); }
public async Task <bool> Add([FromBody] InstitutionAndOwner institutionAndOwner) { int ownerId = AuthenticationService.GetUserId(institutionAndOwner.OwnerToken); return(await institutionService.Add(new Institution { Name = institutionAndOwner.Name, Location = institutionAndOwner.Location }, ownerId)); }