コード例 #1
0
        public long UpdateCountry(CountryObject country)
        {
            try
            {
                if (country == null)
                {
                    return(-2);
                }

                var countryEntity = ModelMapper.Map <CountryObject, Country>(country);
                if (countryEntity == null || countryEntity.Id < 1)
                {
                    return(-2);
                }

                using (var db = new ImportPermitEntities())
                {
                    if (db.Countries.Count(f => f.Name.ToLower().Trim() == country.Name.ToLower().Trim() && f.Id != country.Id) > 0)
                    {
                        return(-3);
                    }

                    db.Countries.Attach(countryEntity);
                    db.Entry(countryEntity).State = EntityState.Modified;
                    db.SaveChanges();
                    return(country.Id);
                }
            }
            catch (Exception ex)
            {
                ErrorLogger.LoggError(ex.StackTrace, ex.Source, ex.Message);
                return(0);
            }
        }
コード例 #2
0
        public void CreateWithRegionInfoTest()
        {
            var i = new RegionInfo("ee-EE");

            o = CountryObjectFactory.Create(i);
            validateResults(i.ThreeLetterISORegionName, i.DisplayName, i.TwoLetterISORegionName);
        }
コード例 #3
0
        public async Task <CountryObject> AddObject(CountryObject o)
        {
            db.Countries.Add(o.DbRecord);
            await db.SaveChangesAsync();

            return(o);
        }
コード例 #4
0
 public long AddCountry(CountryObject country)
 {
     try
     {
         if (country == null)
         {
             return(-2);
         }
         var duplicates = _repository.Count(m => m.Name.Trim().ToLower() == country.Name.Trim().ToLower() && (m.CountryId != country.CountryId));
         if (duplicates > 0)
         {
             return(-3);
         }
         var countryEntity = ModelCrossMapper.Map <CountryObject, Country>(country);
         if (countryEntity == null || string.IsNullOrEmpty(countryEntity.Name))
         {
             return(-2);
         }
         var returnStatus = _repository.Add(countryEntity);
         _uoWork.SaveChanges();
         return(returnStatus.CountryId);
     }
     catch (Exception ex)
     {
         ErrorLogger.LogError(ex.StackTrace, ex.Source, ex.Message);
         return(0);
     }
 }
コード例 #5
0
        private GenericValidator ValidateCountry(CountryObject country)
        {
            var gVal = new GenericValidator();

            try
            {
                if (country.RegionId < 1)
                {
                    gVal.Code  = -1;
                    gVal.Error = "Please select a Region.";
                    return(gVal);
                }



                gVal.Code = 5;
                return(gVal);
            }
            catch (Exception)
            {
                gVal.Code  = -1;
                gVal.Error = "Country Validation failed. Please provide all required fields and try again.";
                return(gVal);
            }
        }
コード例 #6
0
 public CountryCurrencyObject(CountryCurrencyDbRecord dbRecord) : base(dbRecord)
 {
     DbRecord.Country  = DbRecord.Country ?? new CountryDbRecord();
     DbRecord.Currency = DbRecord.Currency ?? new CurrencyDbRecord();
     Country           = new CountryObject(DbRecord.Country);
     Currency          = new CurrencyObject(DbRecord.Currency);
 }
コード例 #7
0
        public long AddCountry(CountryObject country)
        {
            try
            {
                if (country == null)
                {
                    return(-2);
                }

                var countryEntity = ModelMapper.Map <CountryObject, Country>(country);

                if (countryEntity == null)
                {
                    return(-2);
                }

                using (var db = new ImportPermitEntities())
                {
                    if (db.Countries.Count(f => f.Name.ToLower().Trim() == country.Name.ToLower().Trim()) > 0)
                    {
                        return(-3);
                    }
                    var returnStatus = db.Countries.Add(countryEntity);
                    db.SaveChanges();
                    return(returnStatus.Id);
                }
            }
            catch (Exception ex)
            {
                ErrorLogger.LoggError(ex.StackTrace, ex.Source, ex.Message);
                return(0);
            }
        }
コード例 #8
0
 public int UpdateCountry(CountryObject country)
 {
     try
     {
         if (country == null)
         {
             return(-2);
         }
         var duplicates = _repository.Count(m => m.Name.Trim().ToLower() == country.Name.Trim().ToLower() && (m.CountryId != country.CountryId));
         if (duplicates > 0)
         {
             return(-3);
         }
         var countryEntity = ModelCrossMapper.Map <CountryObject, Country>(country);
         if (countryEntity == null || countryEntity.CountryId < 1)
         {
             return(-2);
         }
         _repository.Update(countryEntity);
         _uoWork.SaveChanges();
         return(5);
     }
     catch (Exception ex)
     {
         ErrorLogger.LogError(ex.StackTrace, ex.Source, ex.Message);
         return(-2);
     }
 }
コード例 #9
0
        public ActionResult EditCountry(CountryObject country)
        {
            var gVal = new GenericValidator();

            try
            {
                //if (!ModelState.IsValid)
                //{
                //    gVal.Code = -1;
                //    gVal.Error = "Plese provide all required fields and try again.";
                //    return Json(gVal, JsonRequestBehavior.AllowGet);
                //}

                var stat = ValidateCountry(country);

                if (stat.Code < 1)
                {
                    return(Json(gVal, JsonRequestBehavior.AllowGet));
                }

                if (Session["_country"] == null)
                {
                    gVal.Code  = -1;
                    gVal.Error = "Session has timed out.";
                    return(Json(gVal, JsonRequestBehavior.AllowGet));
                }

                var oldcountry = Session["_country"] as CountryObject;

                if (oldcountry == null)
                {
                    gVal.Code  = -1;
                    gVal.Error = "Session has timed out.";
                    return(Json(gVal, JsonRequestBehavior.AllowGet));
                }

                oldcountry.Name        = country.Name;
                oldcountry.CountryCode = country.CountryCode;
                oldcountry.RegionId    = country.RegionId;

                var docStatus = new CountryServices().UpdateCountry(oldcountry);
                if (docStatus < 1)
                {
                    gVal.Code  = -1;
                    gVal.Error = docStatus == -3 ? "Country already exists." : "Country information could not be updated. Please try again later";
                    return(Json(gVal, JsonRequestBehavior.AllowGet));
                }

                gVal.Code  = oldcountry.Id;
                gVal.Error = "Country information was successfully updated";
                return(Json(gVal, JsonRequestBehavior.AllowGet));
            }
            catch (Exception)
            {
                gVal.Code  = -1;
                gVal.Error = "Country information could not be updated. Please try again later";
                return(Json(gVal, JsonRequestBehavior.AllowGet));
            }
        }
コード例 #10
0
 public static void Disclose(CountryObject countryObject, Side side)
 {
     countryObject.side = side;
     AddDiclosedMoney(side);
     lastDisclosedCountry = countryObject;
     MapController.GetNewCountryColors();
     //TODO:color differenctly
 }
コード例 #11
0
 public ActionResult EditCountry(CountryObject model)
 {
     if (!ModelState.IsValid)
     {
         return(View(model));
     }
     model.Save();
     return(RedirectToAction("Countries"));
 }
コード例 #12
0
        public ActionResult EditCountry(int?id)
        {
            CountryObject model = new CountryObject();

            if (id.HasValue)
            {
                model = MemoryCache.GetCountry(id.Value);
            }
            return(View(model));
        }
コード例 #13
0
ファイル: Country.cs プロジェクト: ComicIronic/Diplomacy
    public void SetupCountry(CountryObject firstTerritory)
    {
        Camera.main.GetComponent <CanvasCreator> ().countries.Add(this);
        Camera.main.GetComponent <CanvasCreator> ().factions [0].AddCountry(this);

        AddTerritory(firstTerritory);
        countryName = firstTerritory.name;

        CreateCountryNode();
    }
コード例 #14
0
        public ActionResult EditCountry(CountryObject country)
        {
            var gVal = new GenericValidator();

            try
            {
                if (ModelState.IsValid)
                {
                    var valStatus = ValidateCountry(country);
                    if (valStatus.Code < 1)
                    {
                        gVal.Code  = -1;
                        gVal.Error = valStatus.Error;
                        return(Json(gVal, JsonRequestBehavior.AllowGet));
                    }

                    if (Session["_country"] == null)
                    {
                        gVal.Code  = -5;
                        gVal.Error = message_Feedback.Session_Time_Out;
                        return(Json(gVal, JsonRequestBehavior.AllowGet));
                    }

                    var oldCountry = Session["_country"] as CountryObject;
                    if (oldCountry == null || oldCountry.CountryId < 1)
                    {
                        gVal.Code  = -5;
                        gVal.Error = message_Feedback.Session_Time_Out;
                        return(Json(gVal, JsonRequestBehavior.AllowGet));
                    }
                    oldCountry.Name = country.Name.Trim();
                    var k = new CountryServices().UpdateCountry(oldCountry);
                    if (k < 1)
                    {
                        gVal.Error = k == -3 ? message_Feedback.Item_Duplicate : message_Feedback.Update_Failure;
                        gVal.Code  = 0;
                        return(Json(gVal, JsonRequestBehavior.AllowGet));
                    }

                    gVal.Code  = k;
                    gVal.Error = message_Feedback.Model_State_Error;
                    return(Json(gVal, JsonRequestBehavior.AllowGet));
                }

                gVal.Code  = -5;
                gVal.Error = message_Feedback.Model_State_Error;
                return(Json(gVal, JsonRequestBehavior.AllowGet));
            }
            catch
            {
                gVal.Code  = 0;
                gVal.Error = message_Feedback.Process_Failed;
                return(Json(gVal, JsonRequestBehavior.AllowGet));
            }
        }
コード例 #15
0
ファイル: CountryService.cs プロジェクト: AdiSha1995/shopmaxi
 public long AddCountry(CountryObject countryAccount)
 {
     try
     {
         return(_countryRepository.AddCountry(countryAccount));
     }
     catch (Exception ex)
     {
         ErrorLogger.LogError(ex.StackTrace, ex.Source, ex.Message);
         return(0);
     }
 }
コード例 #16
0
 public long UpdateCountry(CountryObject country)
 {
     try
     {
         return(_countryManager.UpdateCountry(country));
     }
     catch (Exception ex)
     {
         ErrorLogger.LoggError(ex.StackTrace, ex.Source, ex.Message);
         return(0);
     }
 }
コード例 #17
0
ファイル: CountryService.cs プロジェクト: AdiSha1995/shopmaxi
 public int UpdateCountry(CountryObject country)
 {
     try
     {
         return(_countryRepository.UpdateCountry(country));
     }
     catch (Exception ex)
     {
         ErrorLogger.LogError(ex.StackTrace, ex.Source, ex.Message);
         return(-2);
     }
 }
コード例 #18
0
        public static CountryCurrencyObject Create(CountryObject country, CurrencyObject currency,
                                                   DateTime?validFrom = null, DateTime?validTo = null)
        {
            var o = new CountryCurrencyDbRecord {
                Country   = country?.DbRecord ?? new CountryDbRecord(),
                Currency  = currency?.DbRecord ?? new CurrencyDbRecord(),
                ValidFrom = validFrom ?? DateTime.MinValue,
                ValidTo   = validTo ?? DateTime.MaxValue
            };

            o.CountryID  = o.Country.ID;
            o.CurrencyID = o.Currency.ID;
            return(new CountryCurrencyObject(o));
        }
コード例 #19
0
        public async Task LoadCurrencies(CountryObject country)
        {
            if (country is null)
            {
                return;
            }
            var id         = country.DbRecord?.ID ?? string.Empty;
            var currencies = await dbSet.Include(x => x.Currency).Where(x => x.CountryID == id)
                             .AsNoTracking().ToListAsync();

            foreach (var c in currencies)
            {
                country.CurrencyInUse(new CurrencyObject(c.Currency));
            }
        }
コード例 #20
0
 public void UsedInCountry(CountryObject countryObject)
 {
     if (countryObject is null)
     {
         return;
     }
     if (countryObject.DbRecord.ID == Constants.Unspecified)
     {
         return;
     }
     if (usedInCountries.Find(x => x.DbRecord.ID == countryObject.DbRecord.ID) != null)
     {
         return;
     }
     usedInCountries.Add(countryObject);
 }
コード例 #21
0
        public List <CountryObject> GetCountries()
        {
            try
            {
                using (var db = new ImportPermitEntities())
                {
                    var list      = new List <CountryObject>();
                    var countries = db.Countries.OrderBy(m => m.Name).Include("Cities").ToList();

                    if (!countries.Any())
                    {
                        return(list);
                    }

                    countries.ForEach(c =>
                    {
                        var country = new CountryObject
                        {
                            Id          = c.Id,
                            Name        = c.Name,
                            CityObjects = new List <CityObject>()
                        };
                        if (c.Cities.Any())
                        {
                            c.Cities.ToList().ForEach(ct =>
                            {
                                country.CityObjects.Add(new CityObject
                                {
                                    CityId    = ct.CityId,
                                    Name      = ct.Name,
                                    CountryId = ct.CountryId
                                });
                            });
                        }

                        list.Add(country);
                    });

                    return(list);
                }
            }
            catch (Exception ex)
            {
                ErrorLogger.LoggError(ex.StackTrace, ex.Source, ex.Message);
                return(new List <CountryObject>());
            }
        }
コード例 #22
0
        public static CountryViewModel Create(CountryObject o)
        {
            var v = new CountryViewModel
            {
                Name       = o?.DbRecord.Name,
                Alpha3Code = o?.DbRecord.ID,
                Alpha2Code = o?.DbRecord.Code,
            };

            if (o is null)
            {
                return(v);
            }
            v.ValidFrom = setNullIfExtremum(o.DbRecord.ValidFrom);
            v.ValidTo   = setNullIfExtremum(o.DbRecord.ValidTo);
            return(v);
        }
コード例 #23
0
    static CountryObject CreateCountry(Country country, Side side, int id)
    {
        GameObject    newFort       = new GameObject(sideToName[(int)side]);
        CountryObject countryObject = newFort.AddComponent <CountryObject>();

        countryObject.InitializeFort(country, side, id);

        Vector2Int coordinates = Util.FindCoordinates(country.fort);

        newFort.transform.localPosition = Util.GetPosition(coordinates);

        countryObject.fortHex      = Util.HexExist(coordinates.x, coordinates.y);
        countryObject.fortHex.fort = countryObject;
        ColorFort(country, countryObject, side);

        return(countryObject);
    }
コード例 #24
0
        public void CreateTest()
        {
            var r        = GetRandom.Object <CountryCurrencyDbRecord>();
            var country  = new CountryObject(r.Country);
            var currency = new CurrencyObject(r.Currency);

            var o = CountryCurrencyObjectFactory.Create(country, currency, r.ValidFrom, r.ValidTo);

            Assert.AreEqual(o.DbRecord.ValidFrom, r.ValidFrom);
            Assert.AreEqual(o.DbRecord.ValidTo, r.ValidTo);
            Assert.AreEqual(o.Currency.DbRecord, r.Currency);
            Assert.AreEqual(o.Country.DbRecord, r.Country);
            Assert.AreEqual(o.DbRecord.CountryID, r.Country.ID);
            Assert.AreEqual(o.DbRecord.CurrencyID, r.Currency.ID);
            Assert.AreEqual(o.DbRecord.Country, r.Country);
            Assert.AreEqual(o.DbRecord.Currency, r.Currency);
        }
コード例 #25
0
    //set up a question, given the country and the topic
    public static void setUpHint(CountryObject c, string category)
    {
        Text  questionText = GameObject.Find("QuestionText").GetComponent <Text>();
        Image im           = GameObject.Find("HintImage").GetComponent <Image>();

        im.enabled        = true;
        questionText.text = Category.buildQuestion(category);
        Sprite sprite = Resources.Load <Sprite>(category + "/" + c.countryName);

        im.sprite = sprite;
        AudioClip   countryMusic = Resources.Load <AudioClip>("Sound/Traditional/" + c.countryName);
        AudioSource m            = GameObject.Find("GameMusic").GetComponent <AudioSource>();

        m.clip = countryMusic;
        m.loop = true;
        m.Play();
        resetLights();
    }
コード例 #26
0
 public static void SelectFort(Hex hex, Side side)
 {
     if (hex.fort != null && hex.fort.side == side)
     {
         if (selectedCountry == null)
         {
             selectedCountry = hex.fort;
         }
         else
         {
             selectedCountry = null;
         }
     }
     else
     {
         selectedCountry = null;
     }
 }
コード例 #27
0
    static void ColorFort(Country country, CountryObject fort, Side side)
    {
        for (int i = 0; i < country.hexes.Count; i++)
        {
            Vector2Int coordinates = Util.FindCoordinates(country.hexes[i]);

            /*if (country.fort == country.hexes[i])
             * {
             *  MapController.hexes[coordinates.x, coordinates.y].hexHighlight.color = side == Side.Blue ? Color.blue : Color.red;
             * }
             * else
             * {
             *  MapController.hexes[coordinates.x, coordinates.y].hexHighlight.color = side == Side.Blue ? Color.cyan : Color.magenta;
             * }*/

            MapController.hexes[coordinates.x, coordinates.y].fort = fort;
            fort.hexes[i] = MapController.hexes[coordinates.x, coordinates.y];
        }
    }
コード例 #28
0
        public ActionResult AddCountry(CountryObject country)
        {
            var gVal = new GenericValidator();

            try
            {
                var importerInfo = GetLoggedOnUserInfo();
                if (importerInfo.Id < 1)
                {
                    gVal.Error = "Your session has timed out";
                    gVal.Code  = -1;
                    return(Json(gVal, JsonRequestBehavior.AllowGet));
                }

                var validationResult = ValidateCountry(country);

                if (validationResult.Code == 1)
                {
                    return(Json(validationResult, JsonRequestBehavior.AllowGet));
                }



                var appStatus = new CountryServices().AddCountry(country);
                if (appStatus < 1)
                {
                    validationResult.Code  = -1;
                    validationResult.Error = appStatus == -2 ? "Country upload failed. Please try again." : "The Country Information already exists";
                    return(Json(validationResult, JsonRequestBehavior.AllowGet));
                }

                gVal.Code  = appStatus;
                gVal.Error = "Country was successfully added.";
                return(Json(gVal, JsonRequestBehavior.AllowGet));
            }
            catch (Exception)
            {
                gVal.Error = "Country processing failed. Please try again later";
                gVal.Code  = -1;
                return(Json(gVal, JsonRequestBehavior.AllowGet));
            }
        }
コード例 #29
0
        private GenericValidator ValidateCountry(CountryObject country)
        {
            var gVal = new GenericValidator();

            if (country == null)
            {
                gVal.Code  = -1;
                gVal.Error = message_Feedback.Fatal_Error;
                return(gVal);
            }
            if (string.IsNullOrEmpty(country.Name))
            {
                gVal.Code  = -1;
                gVal.Error = message_Feedback.Country_Name_Error;
                return(gVal);
            }

            gVal.Code = 5;
            return(gVal);
        }
コード例 #30
0
        public static CountryViewModel Create(CountryObject o)
        {
            var v = new CountryViewModel
            {
                Name       = o?.DbRecord.Name,
                Alpha3Code = o?.DbRecord.ID,
                Alpha2Code = o?.DbRecord.Code
            };

            if (o is null)
            {
                return(v);
            }
            v.ValidFrom = setNullIfExtremum(o.DbRecord.ValidFrom);
            v.ValidTo   = setNullIfExtremum(o.DbRecord.ValidTo);
            foreach (var c in o.CurrenciesInUse)
            {
                var currency = CurrencyViewModelFactory.Create(c);
                v.CurrenciesInUse.Add(currency);
            }
            return(v);
        }
コード例 #31
0
ファイル: Country.cs プロジェクト: ComicIronic/Diplomacy
 //If we're moving it into another country and don't want the inbetween
 public void AddTo(CountryObject territory, Country other)
 {
     territories.Remove (territory);
     other.AddTerritory (territory);
 }
コード例 #32
0
ファイル: Country.cs プロジェクト: ComicIronic/Diplomacy
 public void AddTerritory(CountryObject territory)
 {
     territories.Add (territory);
     territory.parentCountry = this;
     territory.ColorToFaction ();
 }
コード例 #33
0
ファイル: Country.cs プロジェクト: ComicIronic/Diplomacy
    public void SetupCountry(CountryObject firstTerritory)
    {
        Camera.main.GetComponent<CanvasCreator> ().countries.Add (this);
        Camera.main.GetComponent<CanvasCreator> ().factions [0].AddCountry (this);

        AddTerritory (firstTerritory);
        countryName = firstTerritory.name;

        CreateCountryNode ();
    }
コード例 #34
0
ファイル: Country.cs プロジェクト: ComicIronic/Diplomacy
 //If we're not moving it into another country but want to split it off
 public void RemoveTerritory(CountryObject territory)
 {
     territories.Remove (territory);
     territory.parentCountry = new Country();
     territory.parentCountry.SetupCountry (territory);
 }