Example #1
0
        public ActionResult SearchResultAllTarget(string search_text, string target = "workers", int type_id = 0)
        {
            if (search_text.Length > 2 && search_text.Length < 200)
            {
                iproby.Data_Model.search_texts search_text_db = new iproby.Data_Model.search_texts();
                search_text_db.search_input = search_text;
                DateTime date_from1 = DateTime.Now;
                search_text_db.date_from = date_from1;
                db.search_texts.Add(search_text_db);
                db.SaveChanges();
                var announ_id_arr = Enumerable.Empty <iproby.Data_Model.announ>().AsQueryable();
                if (type_id == 0)
                {
                    announ_id_arr = (from a in db.announs
                                     where (a.description.Contains(search_text) ||
                                            a.header.Contains(search_text) ||
                                            a.about.Contains(search_text) ||
                                            a.subjects.Contains(search_text))
                                     join db_target in db.announ_target on a.id equals db_target.announ_id
                                     where db_target.target_type.Contains(target)
                                     select a);
                }
                else
                {
                    announ_id_arr = (from a in db.announs
                                     where ((a.description.Contains(search_text) ||
                                             a.header.Contains(search_text) ||
                                             a.about.Contains(search_text) ||
                                             a.subjects.Contains(search_text)) &&
                                            a.type_id == type_id)
                                     join db_target in db.announ_target on a.id equals db_target.announ_id
                                     where db_target.target_type.Contains(target)
                                     select a);
                }
                int announ_id = 0;
                List <iproby.Models.announ_preview> all_announs = new List <iproby.Models.announ_preview>();
                foreach (var item in announ_id_arr)
                {
                    announ_id = item.id;
                    var announ_arr = (from a in db.announs
                                      where a.id == announ_id
                                      select a);
                    iproby.Models.announ_preview announ = new iproby.Models.announ_preview();
                    announ.from_search_flag = 1;
                    foreach (var item_inside in announ_arr)
                    {
                        announ.description = TruncateAtWord(SkipHtml(item_inside.description.Trim()), 360);
                        announ.header      = item_inside.header;
                        announ.announ_id   = item_inside.id;
                        announ.type_id     = item_inside.type_id.Value;
                    }
                    var customer_id_arr = (from a in db.customer_announ
                                           where a.announ_id == announ_id
                                           select a);
                    int      customer_id = 0;
                    DateTime date_from   = DateTime.Now;
                    foreach (var item_inside in customer_id_arr)
                    {
                        customer_id = item_inside.customer_id.Value;
                        date_from   = item_inside.date_from;
                    }
                    announ.customer_id = customer_id;
                    var contact_id_arr = (from a in db.customers
                                          where a.customer_id == customer_id
                                          select a.contact_id);
                    int contact_id = 0;
                    foreach (int item_inside in contact_id_arr)
                    {
                        contact_id = item_inside;
                    }
                    var contact_arr = (from a in db.contacts
                                       where a.contact_id == contact_id
                                       select a);
                    foreach (var item_inside in contact_arr)
                    {
                        announ.first_name  = item_inside.first_name;
                        announ.mobile      = item_inside.mobile;
                        announ.address     = item_inside.address;
                        announ.date_from   = date_from;
                        announ.search_word = search_text;
                        announ.email       = item_inside.email;
                        announ.vkontakte   = (item_inside.vkontakte != null) ? item_inside.vkontakte : "не указан";
                        announ.skype       = (item_inside.skype != null) ? item_inside.skype : "не указан";
                        announ.facebook    = (item_inside.facebook != null) ? item_inside.facebook : "не указан";
                        announ.address     = item_inside.address;
                        announ.avatar      = item_inside.avatar_cropped;
                        announ.date_from   = date_from;
                    }
                    announ.from_search_flag = 1;
                    all_announs.Add(announ);
                }
                ViewData["search_text"] = search_text;

                return(View("~/Views/Catalog/Announs.cshtml", all_announs));
            }
            else
            {
                List <iproby.Models.announ_preview> all_announs = new List <iproby.Models.announ_preview>();
                return(View("~/Views/Catalog/Announs.cshtml", all_announs));
            }
        }
Example #2
0
        public ActionResult SearchResultInTypes(string search_text, int type_id=0)
        {
            ViewBag.type_id = type_id;
            if (type_id != 0)
            {
                if (search_text.Length > 2 && search_text.Length < 200)
                {
                    iproby.Data_Model.search_texts search_text_db = new iproby.Data_Model.search_texts();
                    search_text_db.search_input = search_text;
                    DateTime date_from1 = DateTime.Now;
                    search_text_db.date_from = date_from1;
                    db.search_texts.Add(search_text_db);
                    db.SaveChanges();
                    var announ_id_arr = (from a in db.announs
                                         where ((a.description.Contains(search_text)
                                         || a.header.Contains(search_text)
                                         || a.about.Contains(search_text)
                                         || a.subjects.Contains(search_text))
                                         && a.type_id == type_id)
                                         select a);
                    int announ_id = 0;
                    List<iproby.Models.announ_preview> all_announs = new List<iproby.Models.announ_preview>();
                    foreach (var item in announ_id_arr)
                    {
                        announ_id = item.id;
                        var announ_arr = (from a in db.announs
                                          where a.id == announ_id
                                          select a);
                        iproby.Models.announ_preview announ = new iproby.Models.announ_preview();
                        announ.from_search_flag = 1;
                        announ.type_id = type_id;
                        foreach (var item_inside in announ_arr)
                        {
                            announ.description = TruncateAtWord(SkipHtml(item_inside.description.Trim()), 360);
                            announ.header = item_inside.header;
                            announ.announ_id = item_inside.id;
                        }
                        var customer_id_arr = (from a in db.customer_announ
                                               where a.announ_id == announ_id
                                               select a);
                        int customer_id = 0;
                        DateTime date_from = DateTime.Now;
                        foreach (var item_inside in customer_id_arr)
                        {
                            customer_id = item_inside.customer_id.Value;
                            date_from = item_inside.date_from;
                        }
                        announ.customer_id = customer_id;
                        var contact_id_arr = (from a in db.customers
                                              where a.customer_id == customer_id
                                              select a.contact_id);
                        int contact_id = 0;
                        foreach (int item_inside in contact_id_arr)
                        {
                            contact_id = item_inside;
                        }
                        var contact_arr = (from a in db.contacts
                                           where a.contact_id == contact_id
                                           select a);
                        foreach (var item_inside in contact_arr)
                        {
                            announ.first_name = item_inside.first_name;
                            announ.mobile = item_inside.mobile;
                            announ.address = item_inside.address;
                            announ.date_from = date_from;
                            announ.search_word = search_text;
                            announ.email = item_inside.email;
                            announ.vkontakte = (item_inside.vkontakte != null) ? item_inside.vkontakte : "не указан";
                            announ.skype = (item_inside.skype != null) ? item_inside.skype : "не указан";
                            announ.facebook = (item_inside.facebook != null) ? item_inside.facebook : "не указан";
                            announ.address = item_inside.address;
                            announ.avatar = item_inside.avatar_cropped;
                            announ.date_from = date_from;
                        }
                        all_announs.Add(announ);
                    }

                    return View("~/Views/Catalog/Announs.cshtml", all_announs);
                }
                else
                {
                    List<iproby.Models.announ_preview> all_announs = new List<iproby.Models.announ_preview>();
                    return View("~/Views/Catalog/Announs.cshtml", all_announs);
                }
            }
            else {
                return SearchResultAll(search_text);
            }
        }