public IActionResult CreateExperience([FromBody] Experience experience) { var lang = Request.Headers["language"].ToString(); var errorMessages = new List <string>(); try { var newExp = new Experience { Title_EN = experience.Title_EN, Title_FR = !string.IsNullOrEmpty(experience.Title_FR) ? experience.Title_FR : experience.Title_EN, Company = experience.Company, Country_EN = experience.Country_EN, Country_FR = !string.IsNullOrEmpty(experience.Country_FR) ? experience.Country_FR : experience.Country_EN, City_EN = experience.City_EN, City_FR = !string.IsNullOrEmpty(experience.City_FR) ? experience.City_FR : experience.City_EN, Accomplishments_EN = experience.Accomplishments_EN, Accomplishments_FR = !string.IsNullOrEmpty(experience.Accomplishments_FR) ? experience.Accomplishments_FR : experience.Accomplishments_EN, Responisbilites_EN = experience.Responisbilites_EN, Responisbilites_FR = !string.IsNullOrEmpty(experience.Responisbilites_FR) ? experience.Responisbilites_FR : experience.Responisbilites_EN, StartDate = experience.StartDate, EndDate = experience.EndDate, IsCurrentlyWorking = experience.IsCurrentlyWorking }; var createdExperience = _experienceRepository.Create(newExp); return(Ok(new { createdExperience })); } catch { errorMessages.Add(_translator.GetTranslation("ERROR", lang)); return(BadRequest(new { errors = errorMessages })); } }
public async Task <IActionResult> CreateOneExperience([FromBody] NewExperienceDto createdExpr) { // check to see if the category is valid by checking against the database // if it's invalid, return an error object var category = await _experienceRepository.GetCategoryByNameAsync(createdExpr.Category); if (category == null) { var err = new ErrorObject() { Method = "POST", At = "/api/experiences", StatusCode = 400, Error = "Category is invalid" }; return(BadRequest(err)); } // map the incoming DTO to our actual database model var exprToAdd = _mapper.Map <Experience>(createdExpr); // add the necessary relations for creation //exprToAdd.Id = Guid.NewGuid(); exprToAdd.Category = category; //var profileId = User.Claims.FirstOrDefault(x => x.Type == "profileId").Value; //exprToAdd.ProfileId = Guid.Parse(profileId); exprToAdd.CreatedOn = DateTime.Now; // add the created experience to the database _experienceRepository.Create(exprToAdd); if (!await _experienceRepository.SaveAsync()) { var errMsg = "Error creating an experience"; _logger.Error(errMsg); var err = new ErrorObject() { Method = "POST", At = "/api/experiences", StatusCode = 500, Error = errMsg }; return(StatusCode(500, err)); } return(CreatedAtAction(nameof(GetOneExperience), new { id = exprToAdd.Id }, _mapper.Map <ViewOneExperienceDto>(exprToAdd))); }
public async Task <IActionResult> Post([FromBody] Experience experience) { experienceRepository.Create(experience); unitofwork.commit(); return(Ok(experience)); }
public void Create(Experience entity) { _ExperienceRepository.Create(entity); }