Example #1
0
        public FrayteCountry GetCountryDetail(int countryId)
        {
            FrayteCountry frayteCountry = new FrayteCountry();
            var           country       = dbContext.Countries.Where(p => p.CountryId == countryId).FirstOrDefault();

            if (country != null)
            {
                var countryDocument = dbContext.CountryDocuments.Where(p => p.CountryId == countryId).ToList();

                //To Dos: Need to add public holiday information here
                var countryPublicHoliday = new List <FrayteCountryPublicHoliday>();

                frayteCountry.Air     = countryDocument.Where(p => p.CountryId == country.CountryId && p.ShipmentType == FrayteShipmentType.Air).ToList().Count > 0 ? true : false;
                frayteCountry.Courier = countryDocument.Where(p => p.CountryId == country.CountryId && p.ShipmentType == FrayteShipmentType.Courier).ToList().Count > 0 ? true : false;
                frayteCountry.Expryes = countryDocument.Where(p => p.CountryId == country.CountryId && p.ShipmentType == FrayteShipmentType.Expryes).ToList().Count > 0 ? true : false;
                frayteCountry.Sea     = countryDocument.Where(p => p.CountryId == country.CountryId && p.ShipmentType == FrayteShipmentType.Sea).ToList().Count > 0 ? true : false;

                frayteCountry.CountryId = country.CountryId;
                frayteCountry.Name      = country.CountryName;
                frayteCountry.Code      = country.CountryCode;

                frayteCountry.CountryDocuments = new List <CountryDocument>();
                frayteCountry.CountryDocuments = countryDocument;

                frayteCountry.CountryPublicHolidays = new List <FrayteCountryPublicHoliday>();
                frayteCountry.CountryPublicHolidays = GetCountyPublicHolidayList(countryId);
            }

            return(frayteCountry);
        }
Example #2
0
        public List <FrayteCountry> GetCountryList()
        {
            var lstCountry = dbContext.Countries.ToList();

            var lstCountryDocument = dbContext.CountryDocuments.ToList();

            List <FrayteCountry> lstFrayteCountry = new List <FrayteCountry>();

            foreach (Country country in lstCountry)
            {
                FrayteCountry frayteCountry = new FrayteCountry();
                frayteCountry.Air     = lstCountryDocument.Where(p => p.CountryId == country.CountryId && p.ShipmentType == FrayteShipmentType.Air).ToList().Count > 0 ? true : false;
                frayteCountry.Courier = lstCountryDocument.Where(p => p.CountryId == country.CountryId && p.ShipmentType == FrayteShipmentType.Courier).ToList().Count > 0 ? true : false;
                frayteCountry.Expryes = lstCountryDocument.Where(p => p.CountryId == country.CountryId && p.ShipmentType == FrayteShipmentType.Expryes).ToList().Count > 0 ? true : false;
                frayteCountry.Sea     = lstCountryDocument.Where(p => p.CountryId == country.CountryId && p.ShipmentType == FrayteShipmentType.Sea).ToList().Count > 0 ? true : false;

                frayteCountry.CountryId = country.CountryId;
                frayteCountry.Name      = country.CountryName;
                frayteCountry.Code      = country.CountryCode;

                frayteCountry.CountryDocuments = new List <CountryDocument>();

                lstFrayteCountry.Add(frayteCountry);
            }

            return(lstFrayteCountry);
        }
Example #3
0
        public FrayteCountry GetCountryDetail(int countryId)
        {
            FrayteCountry countryDetail = new FrayteCountry();

            countryDetail = new CountryRepository().GetCountryDetail(countryId);

            return(countryDetail);
        }
Example #4
0
 public FrayteCountry SaveCountry(FrayteCountry frayteCountry)
 {
     return(new CountryRepository().SaveCountry(frayteCountry));
 }
Example #5
0
        public FrayteCountry SaveCountry(FrayteCountry frayteCountry)
        {
            Country saveCountry;

            if (frayteCountry.CountryId > 0)
            {
                saveCountry = dbContext.Countries.Where(p => p.CountryId == frayteCountry.CountryId).FirstOrDefault();

                saveCountry.CountryName = frayteCountry.Name;
                saveCountry.CountryCode = frayteCountry.Code;
            }
            else
            {
                saveCountry = new Country();

                saveCountry.CountryName = frayteCountry.Name;
                saveCountry.CountryCode = frayteCountry.Code;

                dbContext.Countries.Add(saveCountry);
            }

            dbContext.SaveChanges();
            frayteCountry.CountryId = saveCountry.CountryId;

            //After saving the country information, we need to save its document information
            if (frayteCountry.CountryDocuments != null && frayteCountry.CountryDocuments.Count > 0)
            {
                foreach (CountryDocument document in frayteCountry.CountryDocuments)
                {
                    CountryDocument saveDocument;
                    if (document.CountryDocumentId > 0)
                    {
                        saveDocument = dbContext.CountryDocuments.Where(p => p.CountryDocumentId == document.CountryDocumentId).FirstOrDefault();

                        saveDocument.DocumentName = document.DocumentName;
                        saveDocument.ShipmentType = document.ShipmentType;
                    }
                    else
                    {
                        saveDocument = new CountryDocument();

                        saveDocument.CountryId    = frayteCountry.CountryId;
                        saveDocument.DocumentName = document.DocumentName;
                        saveDocument.ShipmentType = document.ShipmentType;

                        dbContext.CountryDocuments.Add(saveDocument);
                    }

                    dbContext.SaveChanges();
                    document.CountryDocumentId = saveDocument.CountryDocumentId;
                }
            }

            if (frayteCountry.CountryPublicHolidays != null && frayteCountry.CountryPublicHolidays.Count > 0)
            {
                foreach (var document in frayteCountry.CountryPublicHolidays)
                {
                    CountryPublicHoliday countrypublicholiday;
                    if (document.CountryPublicHolidayId > 0)
                    {
                        countrypublicholiday = dbContext.CountryPublicHolidays.Where(p => p.CountryPublicHolidayId == document.CountryPublicHolidayId).FirstOrDefault();

                        countrypublicholiday.CountryId         = frayteCountry.CountryId;
                        countrypublicholiday.Description       = document.Description;
                        countrypublicholiday.PublicHolidayDate = document.PublicHolidayDate;
                    }
                    else
                    {
                        countrypublicholiday = new CountryPublicHoliday();

                        countrypublicholiday.CountryId         = frayteCountry.CountryId;
                        countrypublicholiday.Description       = document.Description;
                        countrypublicholiday.PublicHolidayDate = document.PublicHolidayDate;

                        dbContext.CountryPublicHolidays.Add(countrypublicholiday);
                    }

                    dbContext.SaveChanges();
                    document.CountryPublicHolidayId = countrypublicholiday.CountryPublicHolidayId;
                }
            }

            return(frayteCountry);
        }