Ejemplo n.º 1
0
        public Entry Record(Entry a)
        {
            Entry_info info = db.Info.First(x1 => x1.Id == a.Info1_id);
            Entry_img  img  = db.Images.First(x1 => x1.Id == a.Images_id);

            try
            {
                if (info.info_1 != null)
                {
                    a.Info1.Add(info.info_1);
                }
                else
                {
                    throw new IndexOutOfRangeException();
                }
                if (info.info_2 != null)
                {
                    a.Info1.Add(info.info_2);
                }
                else
                {
                    throw new IndexOutOfRangeException();
                }
                if (info.info_3 != null)
                {
                    a.Info1.Add(info.info_3);
                }
                else
                {
                    throw new IndexOutOfRangeException();
                }
                if (info.info_4 != null)
                {
                    a.Info1.Add(info.info_4);
                }
                else
                {
                    throw new IndexOutOfRangeException();
                }
                if (info.info_5 != null)
                {
                    a.Info1.Add(info.info_5);
                }
                else
                {
                    throw new IndexOutOfRangeException();
                }
                if (info.info_6 != null)
                {
                    a.Info1.Add(info.info_6);
                }
                else
                {
                    throw new IndexOutOfRangeException();
                }
                if (info.info_7 != null)
                {
                    a.Info1.Add(info.info_7);
                }
                else
                {
                    throw new IndexOutOfRangeException();
                }
                if (info.info_8 != null)
                {
                    a.Info1.Add(info.info_8);
                }
                else
                {
                    throw new IndexOutOfRangeException();
                }
                if (info.info_9 != null)
                {
                    a.Info1.Add(info.info_9);
                }
                else
                {
                    throw new IndexOutOfRangeException();
                }
                if (info.info_10 != null)
                {
                    a.Info1.Add(info.info_10);
                }
                else
                {
                    throw new IndexOutOfRangeException();
                }
            }
            catch
            {
            }
            info = db.Info.First(x1 => x1.Id == a.Info2_id);

            try
            {
                if (info.info_1 != null)
                {
                    a.Info2.Add(info.info_1);
                }
                else
                {
                    throw new IndexOutOfRangeException();
                }
                if (info.info_2 != null)
                {
                    a.Info2.Add(info.info_2);
                }
                else
                {
                    throw new IndexOutOfRangeException();
                }
                if (info.info_3 != null)
                {
                    a.Info2.Add(info.info_3);
                }
                else
                {
                    throw new IndexOutOfRangeException();
                }
                if (info.info_4 != null)
                {
                    a.Info2.Add(info.info_4);
                }
                else
                {
                    throw new IndexOutOfRangeException();
                }
                if (info.info_5 != null)
                {
                    a.Info2.Add(info.info_5);
                }
                else
                {
                    throw new IndexOutOfRangeException();
                }
                if (info.info_6 != null)
                {
                    a.Info2.Add(info.info_6);
                }
                else
                {
                    throw new IndexOutOfRangeException();
                }
                if (info.info_7 != null)
                {
                    a.Info2.Add(info.info_7);
                }
                else
                {
                    throw new IndexOutOfRangeException();
                }
                if (info.info_8 != null)
                {
                    a.Info2.Add(info.info_8);
                }
                else
                {
                    throw new IndexOutOfRangeException();
                }
                if (info.info_9 != null)
                {
                    a.Info2.Add(info.info_9);
                }
                else
                {
                    throw new IndexOutOfRangeException();
                }
                if (info.info_10 != null)
                {
                    a.Info2.Add(info.info_10);
                }
                else
                {
                    throw new IndexOutOfRangeException();
                }
            }
            catch
            {
            }
            info = db.Info.First(x1 => x1.Id == a.Info3_id);

            try
            {
                if (info.info_1 != null)
                {
                    a.Info3.Add(info.info_1);
                }
                else
                {
                    throw new IndexOutOfRangeException();
                }
                if (info.info_2 != null)
                {
                    a.Info3.Add(info.info_2);
                }
                else
                {
                    throw new IndexOutOfRangeException();
                }
                if (info.info_3 != null)
                {
                    a.Info3.Add(info.info_3);
                }
                else
                {
                    throw new IndexOutOfRangeException();
                }
                if (info.info_4 != null)
                {
                    a.Info3.Add(info.info_4);
                }
                else
                {
                    throw new IndexOutOfRangeException();
                }
                if (info.info_5 != null)
                {
                    a.Info3.Add(info.info_5);
                }
                else
                {
                    throw new IndexOutOfRangeException();
                }
                if (info.info_6 != null)
                {
                    a.Info3.Add(info.info_6);
                }
                else
                {
                    throw new IndexOutOfRangeException();
                }
                if (info.info_7 != null)
                {
                    a.Info3.Add(info.info_7);
                }
                else
                {
                    throw new IndexOutOfRangeException();
                }
                if (info.info_8 != null)
                {
                    a.Info3.Add(info.info_8);
                }
                else
                {
                    throw new IndexOutOfRangeException();
                }
                if (info.info_9 != null)
                {
                    a.Info3.Add(info.info_9);
                }
                else
                {
                    throw new IndexOutOfRangeException();
                }
                if (info.info_10 != null)
                {
                    a.Info3.Add(info.info_10);
                }
                else
                {
                    throw new IndexOutOfRangeException();
                }
            }
            catch
            {
            }
            info = db.Info.First(x1 => x1.Id == a.Info4_id);

            try
            {
                if (info.info_1 != null)
                {
                    a.Info4.Add(info.info_1);
                }
                else
                {
                    throw new IndexOutOfRangeException();
                }
                if (info.info_2 != null)
                {
                    a.Info4.Add(info.info_2);
                }
                else
                {
                    throw new IndexOutOfRangeException();
                }
                if (info.info_3 != null)
                {
                    a.Info4.Add(info.info_3);
                }
                else
                {
                    throw new IndexOutOfRangeException();
                }
                if (info.info_4 != null)
                {
                    a.Info4.Add(info.info_4);
                }
                else
                {
                    throw new IndexOutOfRangeException();
                }
                if (info.info_5 != null)
                {
                    a.Info4.Add(info.info_5);
                }
                else
                {
                    throw new IndexOutOfRangeException();
                }
                if (info.info_6 != null)
                {
                    a.Info4.Add(info.info_6);
                }
                else
                {
                    throw new IndexOutOfRangeException();
                }
                if (info.info_7 != null)
                {
                    a.Info4.Add(info.info_7);
                }
                else
                {
                    throw new IndexOutOfRangeException();
                }
                if (info.info_8 != null)
                {
                    a.Info4.Add(info.info_8);
                }
                else
                {
                    throw new IndexOutOfRangeException();
                }
                if (info.info_9 != null)
                {
                    a.Info4.Add(info.info_9);
                }
                else
                {
                    throw new IndexOutOfRangeException();
                }
                if (info.info_10 != null)
                {
                    a.Info4.Add(info.info_10);
                }
                else
                {
                    throw new IndexOutOfRangeException();
                }
            }
            catch
            {
            }



            try
            {
                if (img.s_1 != null)
                {
                    a.Images.Add(img.s_1);
                }
                else
                {
                    throw new IndexOutOfRangeException();
                }
                if (img.s_2 != null)
                {
                    a.Images.Add(img.s_2);
                }
                else
                {
                    throw new IndexOutOfRangeException();
                }
                if (img.s_3 != null)
                {
                    a.Images.Add(img.s_3);
                }
                else
                {
                    throw new IndexOutOfRangeException();
                }
                if (img.s_4 != null)
                {
                    a.Images.Add(img.s_4);
                }
                else
                {
                    throw new IndexOutOfRangeException();
                }
                if (img.s_5 != null)
                {
                    a.Images.Add(img.s_5);
                }
                else
                {
                    throw new IndexOutOfRangeException();
                }
                if (img.s_6 != null)
                {
                    a.Images.Add(img.s_6);
                }
                else
                {
                    throw new IndexOutOfRangeException();
                }
                if (img.s_7 != null)
                {
                    a.Images.Add(img.s_7);
                }
                else
                {
                    throw new IndexOutOfRangeException();
                }
                if (img.s_8 != null)
                {
                    a.Images.Add(img.s_8);
                }
                else
                {
                    throw new IndexOutOfRangeException();
                }
                if (img.s_9 != null)
                {
                    a.Images.Add(img.s_9);
                }
                else
                {
                    throw new IndexOutOfRangeException();
                }
                if (img.s_10 != null)
                {
                    a.Images.Add(img.s_10);
                }
                else
                {
                    throw new IndexOutOfRangeException();
                }
            }
            catch
            {
            }
            try
            {
                if (img.b_1 != null)
                {
                    a.Images_byte.Add(img.b_1);
                }
                else
                {
                    throw new IndexOutOfRangeException();
                }
                if (img.b_2 != null)
                {
                    a.Images_byte.Add(img.b_2);
                }
                else
                {
                    throw new IndexOutOfRangeException();
                }
                if (img.b_3 != null)
                {
                    a.Images_byte.Add(img.b_3);
                }
                else
                {
                    throw new IndexOutOfRangeException();
                }
                if (img.b_4 != null)
                {
                    a.Images_byte.Add(img.b_4);
                }
                else
                {
                    throw new IndexOutOfRangeException();
                }
                if (img.b_5 != null)
                {
                    a.Images_byte.Add(img.b_5);
                }
                else
                {
                    throw new IndexOutOfRangeException();
                }
                if (img.b_6 != null)
                {
                    a.Images_byte.Add(img.b_6);
                }
                else
                {
                    throw new IndexOutOfRangeException();
                }
                if (img.b_7 != null)
                {
                    a.Images_byte.Add(img.b_7);
                }
                else
                {
                    throw new IndexOutOfRangeException();
                }
                if (img.b_8 != null)
                {
                    a.Images_byte.Add(img.b_8);
                }
                else
                {
                    throw new IndexOutOfRangeException();
                }
                if (img.b_9 != null)
                {
                    a.Images_byte.Add(img.b_9);
                }
                else
                {
                    throw new IndexOutOfRangeException();
                }
                if (img.b_10 != null)
                {
                    a.Images_byte.Add(img.b_10);
                }
                else
                {
                    throw new IndexOutOfRangeException();
                }
            }
            catch
            {
            }



            return(a);
        }
Ejemplo n.º 2
0
        public ActionResult Add_new_ad(Entry a)
        {
            bool error_flag = false;

            TempData["er_Type_of_apartment"] = null;
            TempData["er_Type_ad"]           = null;
            TempData["er_Type"]         = null;
            TempData["er_Price"]        = null;
            TempData["er_Count_rooms"]  = null;
            TempData["er_Phone_number"] = null;
            TempData["er_Place"]        = null;
            //"Жилая недвижимость", "Коммерческая недвижимость", "Загородная недвижимость"
            if (a.Type_of_apartment != "Жилая недвижимость" && a.Type_of_apartment != "Коммерческая недвижимость" && a.Type_of_apartment != "Загородная недвижимость")
            {
                TempData["er_Type_of_apartment"] = "error Type of apartment";
                error_flag = true;
            }
            //"Продажа", "Аренда"
            if (a.Type_ad != "Продажа" && a.Type_ad != "Аренда")
            {
                TempData["er_Type_ad"] = "error Type ad";
                //ModelState.AddModelError("Type_ad", "error Type ad");
                error_flag = true;
            }
            if (a.Type != "Квартиры")
            {
                TempData["er_Type"] = "error Type";
                //ModelState.AddModelError("Type", "error Type");
                error_flag = true;
            }
            if (a.Price == null || a.Price == 0)
            {
                TempData["er_Price"] = "error Price";
                //ModelState.AddModelError("Price", "error Price");
                error_flag = true;
            }

            if (a.Count_rooms == null)
            {
                TempData["er_Count_rooms"] = "error Count rooms";
                //ModelState.AddModelError("Count_rooms", "error Count rooms");
                error_flag = true;
            }
            //Phone_number
            if (a.Phone_number == null)
            {
                TempData["er_Phone_number"] = "error Phone number";
                // ModelState.AddModelError("Phone_number", "error Phone number");
                error_flag = true;
            }
            else
            {
                if (a.Phone_number.Length > 12 || a.Phone_number.Length < 10)
                {
                    TempData["er_Phone_number"] = "error Phone number";
                    // ModelState.AddModelError("Phone_number", "error Phone number");
                    error_flag = true;
                }
            }
            if (a.Place == null)
            {
                TempData["er_Place"] = "error Place";
                //ModelState.AddModelError("Place", "error Place");
                error_flag = true;
            }


            if (error_flag)
            {
                return(View("Add_new_ad", a));
            }
            else
            {
                if (a.Type == "Квартиры")
                {
                    // if(a.Info1.Count>0&&!string.IsNullOrEmpty( a.Info1[0]))//!string.IsNullOrEmpty
                    {
                        //\r\n
                        string[] mas = a.Info1[0].Split(new char[] { '\r', '\n' });
                        a.Info1.Clear();
                        Entry_info info = new Entry_info();
                        try
                        {
                            info.info_1 = mas[0];
                            a.Info1.Add(mas[0]);
                            info.info_2 = mas[2];
                            a.Info1.Add(mas[2]);
                            info.info_3 = mas[4];
                            a.Info1.Add(mas[4]);
                            info.info_4 = mas[6];
                            a.Info1.Add(mas[6]);
                            info.info_5 = mas[8];
                            a.Info1.Add(mas[8]);
                            info.info_6 = mas[10];
                            a.Info1.Add(mas[10]);
                            info.info_7 = mas[12];
                            a.Info1.Add(mas[12]);
                            info.info_8 = mas[14];
                            a.Info1.Add(mas[14]);
                            info.info_9 = mas[16];
                            a.Info1.Add(mas[16]);
                            info.info_10 = mas[18];
                            a.Info1.Add(mas[18]);
                        }
                        catch
                        {
                        }
                        finally
                        {
                            db.Info.Add(info);
                            db.SaveChanges();
                            a.Info1_id = info.Id;
                        }
                    }
                    //if (a.Info2.Count > 0 && !string.IsNullOrEmpty(a.Info2[0]))//!string.IsNullOrEmpty
                    {
                        //\r\n
                        string[] mas = a.Info2[0].Split(new char[] { '\r', '\n' });
                        a.Info2.Clear();
                        Entry_info info = new Entry_info();
                        try
                        {
                            info.info_1 = mas[0];
                            a.Info2.Add(mas[0]);
                            info.info_2 = mas[2];
                            a.Info2.Add(mas[2]);
                            info.info_3 = mas[4];
                            a.Info2.Add(mas[4]);
                            info.info_4 = mas[6];
                            a.Info2.Add(mas[6]);
                            info.info_5 = mas[8];
                            a.Info2.Add(mas[8]);
                            info.info_6 = mas[10];
                            a.Info2.Add(mas[10]);
                            info.info_7 = mas[12];
                            a.Info2.Add(mas[12]);
                            info.info_8 = mas[14];
                            a.Info2.Add(mas[14]);
                            info.info_9 = mas[16];
                            a.Info2.Add(mas[16]);
                            info.info_10 = mas[18];
                            a.Info2.Add(mas[18]);
                        }
                        catch
                        {
                        }
                        finally
                        {
                            db.Info.Add(info);
                            db.SaveChanges();
                            a.Info2_id = info.Id;
                        }
                    }
                    // if (a.Info3.Count > 0 && !string.IsNullOrEmpty(a.Info3[0]))//!string.IsNullOrEmpty
                    {
                        //\r\n
                        string[] mas = a.Info3[0].Split(new char[] { '\r', '\n' });
                        a.Info3.Clear();
                        Entry_info info = new Entry_info();
                        try
                        {
                            info.info_1 = mas[0];
                            a.Info3.Add(mas[0]);
                            info.info_2 = mas[2];
                            a.Info3.Add(mas[2]);
                            info.info_3 = mas[4];
                            a.Info3.Add(mas[4]);
                            info.info_4 = mas[6];
                            a.Info3.Add(mas[6]);
                            info.info_5 = mas[8];
                            a.Info3.Add(mas[8]);
                            info.info_6 = mas[10];
                            a.Info3.Add(mas[10]);
                            info.info_7 = mas[12];
                            a.Info3.Add(mas[12]);
                            info.info_8 = mas[14];
                            a.Info3.Add(mas[14]);
                            info.info_9 = mas[16];
                            a.Info3.Add(mas[16]);
                            info.info_10 = mas[18];
                            a.Info3.Add(mas[18]);
                        }
                        catch
                        {
                        }
                        finally
                        {
                            db.Info.Add(info);
                            db.SaveChanges();
                            a.Info3_id = info.Id;
                        }
                    }
                    //if (a.Info4.Count > 0 && !string.IsNullOrEmpty(a.Info4[0]))//!string.IsNullOrEmpty
                    {
                        //\r\n
                        string[] mas = a.Info4[0].Split(new char[] { '\r', '\n' });
                        a.Info4.Clear();
                        Entry_info info = new Entry_info();
                        try
                        {
                            info.info_1 = mas[0];
                            a.Info4.Add(mas[0]);
                            info.info_2 = mas[2];
                            a.Info4.Add(mas[2]);
                            info.info_3 = mas[4];
                            a.Info4.Add(mas[4]);
                            info.info_4 = mas[6];
                            a.Info4.Add(mas[6]);
                            info.info_5 = mas[8];
                            a.Info4.Add(mas[8]);
                            info.info_6 = mas[10];
                            a.Info4.Add(mas[10]);
                            info.info_7 = mas[12];
                            a.Info4.Add(mas[12]);
                            info.info_8 = mas[14];
                            a.Info4.Add(mas[14]);
                            info.info_9 = mas[16];
                            a.Info4.Add(mas[16]);
                            info.info_10 = mas[18];
                            a.Info4.Add(mas[18]);
                        }
                        catch
                        {
                        }
                        finally
                        {
                            db.Info.Add(info);
                            db.SaveChanges();
                            a.Info4_id = info.Id;
                        }
                    }
                    db.Entries.Add(a);
                    db.SaveChanges();
                }



                return(View("Add_new_ad_img_step", a));
            }
        }