Пример #1
0
        public async Task <AdminResponse> DeletePTO(int id = 0)
        {
            _logger.LogInfo("Trying to delete PTO with id " + id);
            try
            {
                //Get Existing PTO info based on PTO
                PTOInformation ptoInfo = await this._ptoRepository.GetActivePTO(id);

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

                //Soft deleted
                ptoInfo.IsActive = false;

                //Updated PTO information
                _ptoRepository.UpdatePTO(ptoInfo);
                _logger.LogInfo("PTO soft deleted with id " + id);

                //If selected PTO has already been assigned then remove all assigned PTOs with Pass information from mapper table
                _passActivePTOMapper.BulkDeletePTO(ptoInfo.Id);

                _logger.LogInfo("Removed all assigned PTOs with Pass information from mapper table with id " + id);
                return(new AdminResponse(true, string.Format(_messageHandler.GetSuccessMessage(SuccessMessagesEnum.SuccessfullyDeleted))));
            }
            catch (Exception ex)
            {
                _logger.LogError("PTO deleted with id " + id);
                return(new AdminResponse(false, ex.Message));
            }
        }
Пример #2
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));
            }
        }
Пример #3
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));
     }
 }