Exemplo n.º 1
0
        public async Task <AdminResponse> DeletePass(int id = 0)
        {
            _logger.LogInfo("Trying to delete pass with id " + id);
            try
            {
                //Get Existing Pass info based on Pass
                PassInformation passInfo = await this._passRepository.GetActivePass(id);

                //If null then throw exception with invalid information
                if (passInfo == null)
                {
                    throw new Exception(string.Format(_messageHandler.GetMessage(ErrorMessagesEnum.InValidPassInformation)));
                }
                //Soft deleted
                passInfo.IsActive = false;
                //Updated Pass information
                _passRepository.UpdatePass(passInfo);
                _logger.LogInfo("Pass soft deleted with id " + id);
                return(new AdminResponse(true, "Successfully deleted"));
            }
            catch (Exception ex)
            {
                _logger.LogError("Pass deleted with id " + id);
                return(new AdminResponse(false, ex.Message));
            }
        }
Exemplo n.º 2
0
 public AdminResponse CreatePass(PassInformationViewModel passInformation)
 {
     _logger.LogInfo("Trying to add a new pass");
     try
     {
         //Pass remain active whole day(ex: 10/29/2019 23:59:59)
         passInformation.PassExpiredDate = passInformation.PassExpiredDate.AddDays(1).AddSeconds(-1);
         PassInformation passInfo = _mapper.Map <PassInformationViewModel, PassInformation>(passInformation);
         _passRepository.CreatePass(passInfo);
         _logger.LogInfo("Successfully created a new pass");
         AdminResponse response = new AdminResponse(true, string.Format(_messageHandler.GetSuccessMessage(SuccessMessagesEnum.SuccessfullySaved)));
         response.PassInformation = passInformation;
         return(response);
     }
     catch (Exception ex)
     {
         _logger.LogError(ex.Message);
         return(new AdminResponse(false, ex.Message));
     }
 }
Exemplo n.º 3
0
        public async Task <AdminResponse> UpdatePass(PassInformationViewModel passInformation)
        {
            _logger.LogInfo("Trying to update existing pass information");
            try
            {
                _logger.LogInfo("Trying to update existing pass information");
                //Get Existing Pass info based on Pass
                PassInformation passInfo = await this._passRepository.GetActivePass(passInformation.Id);

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

                PassDescription passDesc = new PassDescription();
                //if null then update only Pass information otherwise update Pass description
                if (passInformation.PassDescription != null && passInformation.PassDescription.Count() > 0)
                {
                    //Get Existing Pass desc based on Pass desc id
                    passDesc = passInfo.PassDescription?.Where(p => p.Id == passInformation.PassDescription.FirstOrDefault().Id&& p.SelectedLanguage == passInformation.PassDescription.FirstOrDefault().SelectedLanguage&& p.IsActive).FirstOrDefault();

                    //Pass remain active whole day(ex: 10/29/2019 23:59:59)
                    passInformation.PassExpiredDate = passInformation.PassExpiredDate.AddDays(1).AddSeconds(-1);

                    ////mapped view model to entity
                    passInfo = _mapper.Map <PassInformation>(passInformation);

                    //If null then add new Pass desc with selected language otherwise update existing Pass desc.
                    if (passDesc != null)
                    {
                        //update existing entity from edited by user
                        passDesc = passInfo.PassDescription.FirstOrDefault();

                        //Updated Pass information
                        _passRepository.UpdatePass(passInfo);
                        _logger.LogInfo("Successfully updated Pass information");

                        //Updated pass description
                        _passDescriptionRepository.UpdatePassDesc(passDesc);
                        _logger.LogInfo("Successfully updated Pass Description information");

                        //If selected Pass has already been added then remove all assigned pass along with PTO information from mapper table
                        _passActivePTOMapper.BulkDeletePass(passInfo.Id);
                        _logger.LogInfo("Removed all assigned PTOs with Pass information from mapper table");

                        //Add new updated PTOs for a pass information in Mapper table
                        _passActivePTOMapper.BulkAddPTO(passInfo.PassActivePTOs.ToArray());
                        _logger.LogInfo("Successfully added PTOs information in mapper table");
                    }
                    else
                    {
                        //Added new Pass description if new language selected by user
                        _passDescriptionRepository.AddPassDesc(passInfo.PassDescription.FirstOrDefault());
                        _logger.LogInfo("Successfully added Pass description information");
                    }
                }
                else
                {
                    return(new AdminResponse(false, string.Format(_messageHandler.GetMessage(ErrorMessagesEnum.InValidPassDescription))));
                }

                AdminResponse response = new AdminResponse(true, "Successfully saved");
                response.PassInformation = passInformation;
                return(response);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
                return(new AdminResponse(false, ex.Message));
            }
        }