public ActionResult Edit(Int32 id) { var zones = CachedQueriedData.GetTimezones(id); ViewBag.Timezone = new SelectList(_db.UserTimeZones.ToList(), "UserTimeZoneID", "Display"); ViewBag.CountryID = id; ViewBag.CountryName = _db.Countries.Find(id).DisplayCountryName + " - " + _db.Countries.Find(id).Alpha2Code; return(View(zones)); }
public ActionResult GetTimeZone(int id) { if (SessionNames.IsValidationExceed("GetTimeZone", 100)) { return(Json(null, JsonRequestBehavior.AllowGet)); } var getZones = CachedQueriedData.GetTimezones(id); if (getZones != null) { var represent = getZones.Select(n => new { text = n.Display, id = n.UserTimeZoneID }); return(Json(represent.ToList(), JsonRequestBehavior.AllowGet)); } return(Json(null, JsonRequestBehavior.AllowGet)); }
public ActionResult Edit(int countryId, int timezone, bool hasMultiple) { var country = _db.Countries.Find(countryId); var foundTimeZone = _db.UserTimeZones.Find(timezone); if (foundTimeZone != null) { var addRelation = new CountryTimezoneRelation { CountryID = country.CountryID, UserTimeZoneID = foundTimeZone.UserTimeZoneID }; var anyExist = _db.CountryTimezoneRelations.Any( n => n.UserTimeZoneID == addRelation.UserTimeZoneID && n.CountryID == addRelation.CountryID); if (!anyExist) { //not exist then add _db.CountryTimezoneRelations.Add(addRelation); country.RelatedTimeZoneID = addRelation.UserTimeZoneID; } country.IsSingleTimeZone = !hasMultiple; country.RelatedTimeZoneID = addRelation.UserTimeZoneID; _db.SaveChanges(); } var zones = CachedQueriedData.GetTimezones(countryId); ViewBag.Timezone = new SelectList(_db.UserTimeZones.ToList(), "UserTimeZoneID", "Display"); ViewBag.CountryID = countryId; ViewBag.CountryName = _db.Countries.Find(countryId).DisplayCountryName + " - " + _db.Countries.Find(countryId).Alpha2Code; return(View(zones)); }
public static void LoadTimeZonesIntoMemory() { _dbTimeZones = CachedQueriedData.GetTimezones(); }
/// <summary> /// External Validations /// Register Code Validation /// </summary> /// <param name="model"></param> public static async Task <bool> ExternalUserValidation(RegisterViewModel model, ApplicationDbContext db, ErrorCollector errors = null) { var validOtherConditions = true; if (errors == null) { errors = new ErrorCollector(); } if (!AppVar.Setting.IsRegisterCodeRequiredToRegister) { model.RegistraterCode = Guid.NewGuid(); model.Role = -1; } else { var regCode = db.RegisterCodes.FirstOrDefault( n => n.IsUsed == false && n.RoleID == model.Role && n.RegisterCodeID == model.RegistraterCode && !n.IsExpired); if (regCode != null) { if (regCode.ValidityTill <= DateTime.Now) { // not valid regCode.IsExpired = true; errors.AddMedium(MessageConstants.RegistercCodeExpired, MessageConstants.SolutionContactAdmin); await db.SaveChangesAsync(); validOtherConditions = false; } } else { errors.AddMedium(MessageConstants.RegistercCodeNotValid, MessageConstants.SolutionContactAdmin); validOtherConditions = false; } } //validation for country language var languages = CachedQueriedData.GetLanguages(model.CountryID, 0); if (languages == null) { //select english as default. model.CountryLanguageID = CachedQueriedData.GetDefaultLanguage().CountryLanguageID; } else if (languages.Count > 1) { //it should be selected inside the register panel. validOtherConditions = !(model.CountryLanguageID == 0); //if zero then false. errors.AddMedium("You forgot you set your language."); } else if (languages.Count == 1) { model.CountryLanguageID = languages[0].CountryLanguageID; } //validation for country timzone var timezones = CachedQueriedData.GetTimezones(model.CountryID, 0); if (timezones != null && timezones.Count > 1) { //it should be selected inside the register panel. validOtherConditions = !(model.UserTimeZoneID == 0); //if zero then false. errors.AddMedium("You forgot you set your time zone."); } else if (timezones.Count == 1) { model.UserTimeZoneID = timezones[0].UserTimeZoneID; } else { validOtherConditions = false; errors.AddMedium( "You time zone not found. Please contact with admin and notify him/her about the issue to notify developer."); } if (!validOtherConditions) { AppConfig.SetGlobalError(errors); } return(validOtherConditions); }