Exemplo n.º 1
0
 public static bool addGMH(GMH gmh)
 {
     using (DAL.Charity_DBEntities db = new DAL.Charity_DBEntities())
     {
         db.GMH.Add(Converters.GMHConverter.convertToDal(gmh));
         try
         {
             db.SaveChanges();
             NeedsGmhim ng = new NeedsGmhim();
             ng.category = gmh.CategoryCode;
             ng.Adress   = gmh.Adress;
             needsGmhim.remove(ng);
             return(true);
         }
         catch (DbEntityValidationException ex)
         {
             foreach (var entityValidationErrors in ex.EntityValidationErrors)
             {
                 foreach (var validationError in entityValidationErrors.ValidationErrors)
                 {
                     System.Diagnostics.Debug.WriteLine(
                         "Property: " + validationError.PropertyName + " Error: " + validationError.ErrorMessage);
                 }
             }
             System.Diagnostics.Debug.WriteLine("no");
             return(false);
         }
     }
 }
Exemplo n.º 2
0
 public static void add(NeedsGmhim ng)
 {
     using (DAL.Charity_DBEntities db = new DAL.Charity_DBEntities())
     {
         if (ng.category != null && ng.category != 0)
         {
             db.NeedsGmhim.Add(BL.Converters.GMHConverter.convertToDal(ng));
         }
         db.SaveChanges();
     }
 }
Exemplo n.º 3
0
        public static bool addSearch(searches s)
        {
            using (DAL.Charity_DBEntities db = new DAL.Charity_DBEntities())
            {
                db.Searches.Add(Converters.SearchesConverter.convertToDal(s));
                try
                {
                    db.SaveChanges();
                    int count = 0;
                    foreach (var s1 in db.Searches)
                    {
                        if (s.Category == s1.Category && BL.GoogleMaps.GetDistance(s.Adress, s1.Adress) < 50 && s.fingerPrint != s1.fingerPrint)
                        {
                            count++;
                        }
                    }

                    {
                        if (count >= 5)
                        {
                            NeedsGmhim ng = new NeedsGmhim
                            {
                                Adress   = s.Adress,
                                category = s.Category
                            };
                            System.Diagnostics.Debug.WriteLine(s.Adress);
                            db.NeedsGmhim.Add(BL.Converters.GMHConverter.convertToDal(ng));
                            try
                            {
                                db.SaveChanges();
                                return(true);
                            }
                            catch { return(false); }
                        }
                    }
                    return(false);
                }
                catch (DbEntityValidationException ex)
                {
                    foreach (var entityValidationErrors in ex.EntityValidationErrors)
                    {
                        foreach (var validationError in entityValidationErrors.ValidationErrors)
                        {
                            System.Diagnostics.Debug.WriteLine(
                                "Property: " + validationError.PropertyName + " Error: " + validationError.ErrorMessage);
                        }
                    }
                    System.Diagnostics.Debug.WriteLine("no");
                    return(false);
                }
            }
        }
Exemplo n.º 4
0
 public static void remove(NeedsGmhim ng)
 {
     using (DAL.Charity_DBEntities db = new DAL.Charity_DBEntities())
     {
         foreach (var item in db.NeedsGmhim)
         {
             if (item.CATEGORY == ng.category && BL.GoogleMaps.GetDistance(ng.Adress, item.ADRESS) < 20)
             {
                 db.NeedsGmhim.Remove(item);
                 db.SaveChanges();
             }
         }
     }
 }
Exemplo n.º 5
0
        public static List <GMH> searchGMH(string text, int category, int tatCategory, double CurrentLocation1, double CurrentLocation2, string location, int distance)
        {
            using (DAL.Charity_DBEntities db = new DAL.Charity_DBEntities())
            {
                List <GMH> gmhim = new List <GMH>();
                if (text != "")
                {
                    foreach (var product in db.Products)
                    {
                        if (product.Productname.Equals(text))
                        {
                            foreach (var productToGmh in db.PRODUCTtoGMH)
                            {
                                if (productToGmh.ProductCode == product.ProductCode)
                                {
                                    foreach (var gmh in db.GMH.Where(g => g.GmhCode == productToGmh.GmhCode))
                                    {
                                        gmhim = checkDistance(gmhim, CurrentLocation1, CurrentLocation2, location, BL.Converters.GMHConverter.convertToDTO(gmh), distance);
                                    }
                                }
                            }
                        }
                    }
                }
                if (db.GMH.Where(g => g.CategoryCode == tatCategory) != null)
                {
                    foreach (DAL.GMH gmh in db.GMH.Where(g => g.CategoryCode == tatCategory))
                    {
                        gmhim = checkDistance(gmhim, CurrentLocation1, CurrentLocation2, location, BL.Converters.GMHConverter.convertToDTO(gmh), distance);
                    }
                }

                if (category != 0)
                {
                    List <int> categories = db.CategoryGMH.Where(c => c.MasterCategoryCode == category).Select(c => c.CategoryCode).ToList();
                    if (db.GMH.Where(g => g.CategoryCode == category && categories.Contains(g.CategoryCode)) != null)
                    {
                        foreach (DAL.GMH gmh in db.GMH.Where(g => g.CategoryCode == category || categories.Contains(g.CategoryCode)))
                        {
                            gmhim = checkDistance(gmhim, CurrentLocation1, CurrentLocation2, location, BL.Converters.GMHConverter.convertToDTO(gmh), distance);
                        }
                    }
                }
                if (gmhim.Count == 0)
                {
                    NeedsGmhim ng = new NeedsGmhim();
                    if (CurrentLocation1 != 0)
                    {
                        ng.Adress = CurrentLocation1 + " " + CurrentLocation2;
                    }
                    else
                    {
                        ng.Adress = location;
                    }
                    if (text != "")
                    {
                        ng.category =
                            db.Products.FirstOrDefault
                                (p => p.Productname.Equals(text)).CategoryCode;
                    }
                    else
                    {
                        if (tatCategory != 0)
                        {
                            ng.category = tatCategory;
                        }
                        else
                        {
                            ng.category = category;
                        }
                    }
                    needsGmhim.add(ng);
                }
                return(gmhim.Distinct().ToList());
            }
        }