Пример #1
0
 /// <summary>
 /// Remove Area from database
 /// </summary>
 /// <param name="instance">Area instance</param>
 /// <param name="saveAfterRemove">Save database after removing</param>
 /// <param name="waitUntilSaving">Wait until saving</param>
 public void AreaRemove(Area instance, bool saveAfterRemove = true, bool waitUntilSaving = true)
 {
     AreaRemove(new Area[] { instance }, saveAfterRemove, waitUntilSaving);
 }
Пример #2
0
 /// <summary>
 /// Add Area to database
 /// </summary>
 /// <param name="instance">Area instance</param>
 /// <param name="saveAfterInsert">Save database after insertion</param>
 /// <param name="waitUntilSaving">Wait until saving</param>
 public void AreaAdd(Area instance, bool saveAfterInsert = true, bool waitUntilSaving = true)
 {
     AreaAdd(new Area[] { instance }, saveAfterInsert, waitUntilSaving);
 }
Пример #3
0
 /// <summary>
 /// Create/Get new Area without any link to database
 /// </summary>
 /// <param name="instanceName">Area name</param>
 /// <returns>Area instance</returns>
 public Area AreaNew(string instanceName = null, bool isDefault = false, City city = null)
 {
     try
     {
         var res = new Area() { Name = instanceName, City = city };
         if (city != null)
         {
             //if (Context.Entry(city).State != EntityState.Detached)
                 city.Areas.Add(res);
             //else
             //    res.City = city;
         }
         return res;
     }
     catch (Exception ex)
     {
         Helpers.Log.Add(ex, string.Format("Repository.AreaNew(instanceName='{0}',city='{1}')", instanceName ?? "NULL", city == null ? "NULL" : city.ToString()));
         throw;
     }
 }
Пример #4
0
 /// <summary>
 /// Get Streets by Street names
 /// </summary>
 /// <param name="instanceNames">Streets name array</param>
 /// <returns>Street array</returns>
 public IQueryable<Street> StreetGet(IEnumerable<string> instanceNames, Area area)
 {
     var inst = instanceNames.Select(n => n.ToUpper()).Distinct();
     var res = StreetGet()
             .Where(s => inst.Contains(s.Name.ToUpper()));
     if (area != null)
     {
         //var res2 = res.Where(s => s.AreaID == area.AreaID);
         //var ent = Context.Entry(area);
         //if ((ent.State == EntityState.Added || ent.State == EntityState.Detached) || ((ent.State == EntityState.Modified || ent.State == EntityState.Unchanged) && Context.Entry(area).Collection(nameof(area.Streets)).IsLoaded))
         //{
             var subRes = area.Streets
                 .Join(inst, s => s.Name.ToUpper(), i => i, (s, i) => s);
             return subRes.AsQueryable();
         //}
         //else
         //    return res2;
     } else
         return res;
 }
Пример #5
0
 /// <summary>
 /// Get Street by name
 /// </summary>
 /// <param name="instanceName">Street name</param>
 /// <returns>Street instance</returns>
 public Street StreetGet(string instanceName, Area area)
 {
     return StreetGet(new string[] { instanceName }, area).SingleOrDefault();
 }
Пример #6
0
        /// <summary>
        /// Create/Get new Street without any link to database
        /// </summary>
        /// <param name="instanceName">Street name</param>
        /// <param name="area">Area to Street add</param>
        /// <returns>Street instance</returns>
        public Street StreetNew(string instanceName = null, Area area = null)
        {
            try
            {
                var res = new Street() { Area = area, Name = instanceName };
                if (area != null)
                {
//                    if (Context.Entry(area).State != EntityState.Detached)
                        area.Streets.Add(res);
                    //else
                    //    res.Area = area;
                }
                return res;
            }
            catch (Exception ex)
            {
                Helpers.Log.Add(ex, string.Format("Repository.StreetNew(instanceName='{0}',area='{1}')", instanceName ?? "NULL", area == null ? "NULL" : area.ToString()));
                throw;
            }
        }