public ProcessResult(int id, bool succeeded, Translation message, int? affectedObjectId = null)
 {
     Id = id;
     Succeeded = succeeded;
     Message = message;
     AffectedObjectId = affectedObjectId;
 }
 protected static string GetTranslation(Culture culture, Translation translation)
 {
     switch (culture)
     {
         case Culture.En:
             return translation.En;
         case Culture.Ru:
             return translation.Ru;
         default:
             return null;
     }
 }
 public string Create(string name, string ids)
 {
     Culture culture = DefineLanguage(HttpContext);
     if (!HttpContext.Request.IsAjaxRequest())
         return ToJson(SProcessResult.Convert(ProcessResults.Error,culture));
     User user = DefineUser(HttpContext);
     var places = ids.Split(' ');
     var translation = new Translation(name, name);
     ProcessResult result = DataManager.Routes.CreateRoute(new Route { Author = user.Id, Translation = translation }, places);
     if (result.Succeeded)
         CleanCookies();
     return ToJson(SProcessResult.Convert(result, culture));
 }
 public ProcessResult AddRegion(string nameRussian, string nameEnglish, int countryId, HttpPostedFileBase imageUpload, HttpServerUtilityBase server)
 {
     if (String.IsNullOrWhiteSpace(nameRussian) || String.IsNullOrWhiteSpace(nameEnglish))
         return ProcessResults.TitleCannotBeEmpty;
     var region = GetRegion(nameRussian, nameEnglish,countryId);
     if (region != null)
         return ProcessResults.RegionAlreadyExists;
     var t = new Translation { En = nameEnglish, Ru = nameRussian };
     t = Data.Translations.Add(t);
     Data.SaveChanges();
     region = Data.Regions.Add(new Region { Name = t.Id, CountryId = countryId });
     Data.SaveChanges();
     if (imageUpload != null)
     {
         if (imageUpload.ContentLength <= 0 || !SecurityManager.IsImage(imageUpload))
             return ProcessResults.InvalidImageFormat;
         region.Image = SaveImage(region.Id, StaticSettings.RegionsUploadFolderPath, imageUpload, server);
         Data.SaveChanges();
     }
     ProcessResult result = ProcessResults.RegionAdded;
     result.AffectedObjectId = region.Id;
     return result;
 }
 public ProcessResult MakeRoutePublic(int routeId, int userId, Translation translation)
 {
     User user = DataManager.Users.Find(userId);
     if (user == null)
         return ProcessResults.UserNotFound;
     if (user.HasLowExperience)
         return ProcessResults.LowExperience;
     Route route = GetRoute(routeId);
     if (route == null)
         return ProcessResults.RouteNotFound;
     if (user.Id != route.Author)
         return ProcessResults.InvalidAuthor;
     if (route.Status == RouteStatus.Public.Id)
         return ProcessResults.RouteAlreadyPublic;
     route.Status = (short)RouteStatus.Public.Id;
     route.Translation.Copy(translation);
     Data.SaveChanges();
     return ProcessResults.RouteIsPublicNow;
 }
 public ActionResult MakeRoutePublic(int id,Translation translation)
 {
     User user = DefineUser(HttpContext);
     if (user == null)
         return RedirectToAction("LogIn", "User");
     ProcessResult result = DataManager.Routes.MakeRoutePublic(id, user.Id,translation);
     TempData["result"] = result;
     return RedirectToAction("Bookmarks");
 }
 public ListItem(int id, Translation name)
 {
     Id = id;
     Name = name;
 }
 private bool Contains(Translation translation, Culture culture, params string[] keys)
 {
     return keys.All(key => GetTranslation(culture, translation).ToUpper().Contains(key.ToUpper()));
 }
 protected bool Contains(Translation translation, string s)
 {
     return (from Culture culture in Enum.GetValues(typeof(Culture)) select Contains(translation, s, culture)).Any(b => b);
 }
 protected bool Contains(Translation translation, string s, Culture culture)
 {
     string[] keys = s.Split(' ');
     return(Contains(translation, culture, keys));
 }
 public Place GetPlace(Translation translation, int regionId)
 {
     return Data.Places.FirstOrDefault(x => (x.Translation.En == translation.En || x.Translation.Ru == translation.Ru) && x.RegionId == regionId);
 }
 public string MakeRoutePublic(string token, int routeId, int userId, Translation translation, Culture culture = Culture.En)
 {
     if (!CheckToken(token)) return null;
     return ToJson(SProcessResult.Convert(DataManager.Routes.MakeRoutePublic(routeId, userId, translation), culture));
 }
Beispiel #13
0
 public PlaceType(short id, Translation translation)
 {
     Id = id;
     Translation = translation;
 }
 protected bool Contains(Translation translation, string s)
 {
     return((from Culture culture in Enum.GetValues(typeof(Culture)) select Contains(translation, s, culture)).Any(b => b));
 }
 public static bool IsInValid(Translation translation)
 {
     return translation == null
            || String.IsNullOrWhiteSpace(translation.En)
            || String.IsNullOrWhiteSpace(translation.Ru);
 }
 protected bool Contains(Translation translation, string s, Culture culture)
 {
     string[] keys = s.Split(' ');
     return Contains(translation, culture, keys);
 }
 public void Copy(Translation translation)
 {
     En = translation.En;
     Ru = translation.Ru;
 }
 private bool Contains(Translation translation, Culture culture, params string[] keys)
 {
     return(keys.All(key => GetTranslation(culture, translation).ToUpper().Contains(key.ToUpper())));
 }