Exemple #1
0
 static void PrintListInfoAboutSimilarProducts(Author2 aMsSql2)
 {
     Console.WriteLine("\n Инорфмация о всех товарах производителя:");
     foreach (Product2 pr in aMsSql2.Product2)
     {
         Console.WriteLine(" - " + pr.title.Replace("  ", "") + " " + pr.price.Replace("  ", "") + " руб.");
     }
 }
Exemple #2
0
        public ActionResult DeleteConfirmed(int id)
        {
            Author2 author2 = db.Author2.Find(id);

            db.Author2.Remove(author2);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Exemple #3
0
 public ActionResult Edit([Bind(Include = "ID,Title,Language")] Author2 author2)
 {
     if (ModelState.IsValid)
     {
         db.Entry(author2).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(author2));
 }
Exemple #4
0
        public ActionResult Create([Bind(Include = "ID,Title,Language")] Author2 author2)
        {
            if (ModelState.IsValid)
            {
                db.Author2.Add(author2);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(author2));
        }
Exemple #5
0
        // GET: Author2/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Author2 author2 = db.Author2.Find(id);

            if (author2 == null)
            {
                return(HttpNotFound());
            }
            return(View(author2));
        }
Exemple #6
0
        static void InsertInMSSQL(MyProduct p) //записываем в MSSQL
        {
            //ms sql
            ulmartDBEntities2 context = new ulmartDBEntities2();

            //производитель
            Author2 aMsSql;

            //проверяем есть ли уже в базе производитель, если нет - то и товара тоже нет
            aMsSql = context.Author2.FirstOrDefault(x => x.author == p.Author);
            if (aMsSql == null) //нет в базе, узнаем новый id для него, добавляем производителя
            {
                aMsSql        = new Author2();
                aMsSql.author = p.Author;
                context.Author2.Add(aMsSql);

                context.SaveChanges(); // вдруг еще не было производителей!
            }


            //товар
            Product2 pMsSql = new Product2();

            pMsSql.title   = p.Title;
            pMsSql.country = p.Country;
            pMsSql.price   = p.Price;
            pMsSql.id      = p.Id;
            pMsSql.author  = aMsSql.id;
            //Запис товар
            Author2 aMsSql2 = context.Author2.Single(d => d.id == aMsSql.id);

            aMsSql2.Product2.Add(pMsSql);

            context.SaveChanges();

            PrintListInfoAboutSimilarProducts(aMsSql2); //печатает инфу о похожих товарах
        }
Exemple #7
0
                public List <(string name, string surnames)> GetAuthors()
                {
                    List <(string name, string surnames)> authorsFinal = new List <(string name, string surnames)>();

                    // o --> {{ "authorUrl": "https://ieeexplore.ieee.org/author/37600583700", "id": 37600583700,"full_name": "Ying-Nong Chen","author_order": 1}}
                    foreach (Object o in authors)
                    {
                        string name         = "";
                        string surnames     = "";
                        string completeName = "";

                        Author2 author = JsonConvert.DeserializeObject <Author2>(o.ToString());
                        completeName = author.full_name;

                        name     = GetName(completeName);
                        surnames = GetSurnames(completeName);

                        authorsFinal.Add((name, surnames));
                    }

                    return(authorsFinal);

                    string GetName(string completeName)
                    {
                        string[] splittedName = completeName.Split(' ');

                        if (splittedName.Length == 0)
                        {
                            return("");
                        }

                        if (splittedName.Length > 1 && splittedName[1].Contains('.'))
                        {
                            return(splittedName.Length > 1 ? splittedName[0] + " " + splittedName[1] : splittedName[0]);
                        }
                        else
                        {
                            return(splittedName[0]);
                        }
                    }

                    string GetSurnames(string completeName)
                    {
                        string[] splittedName = completeName.Split(' ');
                        string   surnames     = "";

                        if (splittedName.Length <= 1)
                        {
                            return("");
                        }

                        if (splittedName[1].Contains('.'))
                        {
                            for (int i = 2; i < splittedName.Length; i++)
                            {
                                surnames += splittedName[i] + " ";
                            }
                        }
                        else
                        {
                            for (int i = 1; i < splittedName.Length; i++)
                            {
                                surnames += splittedName[i] + " ";
                            }
                        }

                        return(surnames.TrimEnd());
                    }
                }