Example #1
0
        public IActionResult UpdateExperience([FromBody] Experience experience)
        {
            var lang          = Request.Headers["language"].ToString();
            var errorMessages = new List <string>();

            try
            {
                var exp = _experienceRepository.FindById(experience.Id);
                if (exp == null)
                {
                    return(NotFound());
                }


                exp.Title_EN           = experience.Title_EN;
                exp.Title_FR           = !string.IsNullOrEmpty(experience.Title_FR) ? experience.Title_FR : experience.Title_EN;
                exp.Company            = experience.Company;
                exp.Country_EN         = experience.Country_EN;
                exp.Country_FR         = !string.IsNullOrEmpty(experience.Country_FR) ? experience.Country_FR : experience.Country_EN;
                exp.City_EN            = experience.City_EN;
                exp.City_FR            = !string.IsNullOrEmpty(experience.City_FR) ? experience.City_FR : experience.City_EN;
                exp.Accomplishments_EN = experience.Accomplishments_EN;
                exp.Accomplishments_FR = !string.IsNullOrEmpty(experience.Accomplishments_FR) ? experience.Accomplishments_FR : experience.Accomplishments_EN;
                exp.Responisbilites_EN = experience.Responisbilites_EN;
                exp.Responisbilites_FR = !string.IsNullOrEmpty(experience.Responisbilites_FR) ? experience.Responisbilites_FR : experience.Responisbilites_EN;
                exp.StartDate          = experience.StartDate;
                exp.EndDate            = experience.EndDate;
                exp.IsCurrentlyWorking = experience.IsCurrentlyWorking;

                var updatedExperience = _experienceRepository.Update(exp);

                return(Ok(new { updatedExperience }));
            }
            catch
            {
                errorMessages.Add(_translator.GetTranslation("ERROR", lang));
                return(BadRequest(new { errors = errorMessages }));
            }
        }
Example #2
0
        public async Task <ExperienceResponse> UpdateAsync(int id, Experience experience)
        {
            var existingExperience = await _experienceRepository.FindById(id);

            if (existingExperience == null)
            {
                return(new ExperienceResponse("Complaint not found"));
            }

            existingExperience.Description = experience.Description;

            try
            {
                _experienceRepository.Update(existingExperience);
                await _unitOfWork.CompleteAsync();

                return(new ExperienceResponse(existingExperience));
            }
            catch (Exception ex)
            {
                return(new ExperienceResponse($"An error ocurred while updating experience: {ex.Message}"));
            }
        }