Beispiel #1
0
        public async Task <AdminResponse> UpdatePTO(PTOInformationViewModel ptoInformation)
        {
            _logger.LogInfo("Trying to update existing PTO information");
            try
            {
                //Get Existing PTO info based on PTO
                PTOInformation ptoInfo = await this._ptoRepository.GetActivePTO(ptoInformation.Id);

                //If null then throw exception with invalid information
                if (ptoInfo == null)
                {
                    return(new AdminResponse(false, string.Format(_messageHandler.GetMessage(ErrorMessagesEnum.InValidPTOInformation))));
                }

                PTODescription ptoDesc = new PTODescription();
                //if null then update only PTO information otherwise update PTO description
                if (ptoInformation.PTODescription != null && ptoInformation.PTODescription.Count() > 0)
                {
                    //Get Existing PTO desc based on PTO desc id
                    ptoDesc = ptoInfo.PTODescription?.Where(p => p.Id == ptoInformation.PTODescription.FirstOrDefault().Id&& p.SelectedLanguage == ptoInformation.PTODescription.FirstOrDefault().SelectedLanguage&& p.IsActive).FirstOrDefault();

                    ////mapped view model to entity
                    ptoInfo = _mapper.Map <PTOInformation>(ptoInformation);

                    //If null then add new PTO desc with selected language otherwise update existing PTO desc.
                    if (ptoDesc != null)
                    {
                        //update existing entity from edited by user
                        ptoDesc = ptoInfo.PTODescription.FirstOrDefault();

                        //Updated PTO information
                        _ptoRepository.UpdatePTO(ptoInfo);
                        _logger.LogInfo("Successfully updated PTO information");

                        //Updated PTO description
                        _ptoDescriptionRepository.UpdatePTODesc(ptoDesc);
                        _logger.LogInfo("Successfully updated PTO Description information");
                    }
                    else
                    {
                        //Added new PTO description if new language selected by user
                        _ptoDescriptionRepository.AddPTODesc(ptoInfo.PTODescription.FirstOrDefault());
                        _logger.LogInfo("Successfully added PTO description information");
                    }
                }
                else
                {
                    return(new AdminResponse(false, string.Format(_messageHandler.GetMessage(ErrorMessagesEnum.InValidPTODescription))));
                }

                AdminResponse response = new AdminResponse(true, string.Format(_messageHandler.GetSuccessMessage(SuccessMessagesEnum.SuccessfullySaved)));
                response.PTOInformation = ptoInformation;
                return(response);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
                return(new AdminResponse(false, ex.Message));
            }
        }
Beispiel #2
0
        public ActionResult <AdminResponse> CreateNewPTO([FromBody] PTOInformationViewModel ptoInformation)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(string.Format(_messageHandler.GetMessage(ErrorMessagesEnum.ModelValidation), "", ModelState.Values.First().Errors.First().ErrorMessage)));
            }
            var response = _ptoService.CreatePTO(ptoInformation);

            return(Ok(response));
        }
Beispiel #3
0
        public async Task <ActionResult <AdminResponse> > UpdatePTOInformation([FromBody] PTOInformationViewModel ptoInformation)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(string.Format(_messageHandler.GetMessage(ErrorMessagesEnum.ModelValidation), "", ModelState.Values.First().Errors.First().ErrorMessage)));
            }
            if (ptoInformation.Id <= 0)
            {
                return(BadRequest(string.Format(_messageHandler.GetMessage(ErrorMessagesEnum.NotValidInformations))));
            }
            var response = await _ptoService.UpdatePTO(ptoInformation);

            return(Ok(response));
        }
Beispiel #4
0
        public async Task <PTOInformationViewModel> GetActivePTO(int lang, int id)
        {
            _logger.LogInfo("Trying to get active PTOs with id " + id + " on language " + lang);
            try
            {
                //Get PTO information based on id and filter PTO description by selected language
                PTOInformationViewModel ptoInformation = _mapper.Map <PTOInformation, PTOInformationViewModel>(await _ptoRepository.GetActivePTO(id));

                //Filter based on language from the paginated result.
                ptoInformation?.PTODescription?.FirstOrDefault(p => p.SelectedLanguage == lang);
                _logger.LogInfo("Retrieved active PTO with id " + id + " on language " + lang);
                return(ptoInformation);
            }
            catch (Exception ex)
            {
                _logger.LogInfo(ex.Message);
                return(null);
            }
        }
Beispiel #5
0
 public AdminResponse CreatePTO(PTOInformationViewModel ptoInformation)
 {
     _logger.LogInfo("Trying to add a new PTO");
     try
     {
         if (ptoInformation.PTODescription.Count() == 0)
         {
             throw new Exception(string.Format(_messageHandler.GetMessage(ErrorMessagesEnum.InValidPTODescription)));
         }
         PTOInformation ptoInfo = _mapper.Map <PTOInformation>(ptoInformation);
         _ptoRepository.CreatePTO(ptoInfo);
         _logger.LogInfo("Successfully created a new PTO");
         AdminResponse response = new AdminResponse(true, string.Format(_messageHandler.GetSuccessMessage(SuccessMessagesEnum.SuccessfullySaved)));
         response.PTOInformation = ptoInformation;
         return(response);
     }
     catch (Exception ex)
     {
         _logger.LogError(ex.Message);
         return(new AdminResponse(false, ex.Message));
     }
 }