Exemplo n.º 1
0
        public ActionResult WordTranslate(int Id)
        {
            var    words      = db.Words.Where(s => s.CategoryID == Id).ToList();
            int    countWords = words.Count;
            int    wordid;
            Random rand = new Random();

            Words[] wordsarrwy = new Words[5];
            List <Quastion <Words> > quastions = new List <Quastion <Words> >();

            using (MaterialContext dbcontext = new MaterialContext())
            {
                int countword = db.Words.Count();
                wordsarrwy[0] = words[0];
                for (int i = 0; i < countWords; i++)
                {
                    for (int j = 1; j < 5; j++)
                    {
                        wordid        = rand.Next(1, 200);
                        wordsarrwy[j] = db.Words.FirstOrDefault(w => w.Id == wordid);
                    }
                    int word = rand.Next(dbcontext.Words.Count());
                    quastions.Add(new Quastion <Words>(words[i], wordsarrwy));
                }
            }
            return(View(quastions));
        }
 public ActionResult GrammerTest(int id)
 {
     using (MaterialContext db = new MaterialContext())
     {
         try
         {
             GrammerText grammer = db.GrammerTexts.FirstOrDefault(u => u.Id == id);
             var         quiz    = db.Quizs.Where(s => s.GrammerId == grammer.Id).FirstOrDefault();
             ViewBag.Title = quiz.QuizName;
             IQueryable <QuestionModel> questions = db.Questions.Where(q => q.QuizID == quiz.QuizID)
                                                    .Select(q => new QuestionModel
             {
                 QuestionID   = q.QuestionID,
                 QuestionText = q.QuestionText,
                 Choices      = q.Choices.Select(c => new ChoiceModel
                 {
                     ChoiceID   = c.ChoiceID,
                     ChoiceText = c.ChoiceText
                 }).ToList()
             });
             TestTextModel testText = new TestTextModel();
             testText.Text      = null;
             testText.Questions = questions.ToList();
             return(View("TestsText", testText));
         }
         catch (Exception ex)
         {
             return(View("TestsText"));
         }
     }
 }
        public ActionResult TestsText(List <AnswerMV> resultQuiz)
        {
            using (MaterialContext db = new MaterialContext())
            {
                int             count           = 0;
                List <AnswerMV> finalResultQuiz = new List <AnswerMV>();
                foreach (AnswerMV answser in resultQuiz)
                {
                    AnswerMV result = db.Answers.Where(a => a.QuestionID == answser.QuestionID).Select(a => new AnswerMV
                    {
                        QuestionID = a.QuestionID.Value,
                        AnswerQ    = a.AnswerText,
                        isCorrect  = (answser.AnswerQ.ToLower().Equals(a.AnswerText.ToLower()))
                    }).FirstOrDefault();

                    finalResultQuiz.Add(result);
                    if (result.isCorrect)
                    {
                        count++;
                    }
                }
                SetPXLevel(count);


                return(Json(new { result = finalResultQuiz }, JsonRequestBehavior.AllowGet));
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Gather all the textures in the node hierarchy, even the ones behind the generics.
        /// </summary>
        /// <param name="node">The node to look into.</param>
        /// <returns>A collection of MaterialTextureNode.</returns>
        private IEnumerable <MaterialTextureNode> GatherTextureValuesWithGenerics(IMaterialNode node)
        {
            var materialContext = new MaterialContext {
                Material = Material, ExploreGenerics = true
            };

            return(GatherTextures(node, materialContext));
        }
 //words
 #region
 public ActionResult AllDictionary()
 {
     Session["WordQuestions"] = null;
     using (MaterialContext db = new MaterialContext())
     {
         List <CategoryWord> viewModel = db.CategoryWords.ToList();
         return(View(viewModel));
     }
 }
Exemplo n.º 6
0
        public static bool ChangeGremmer(int Id, string Name, string Text)
        {
            MaterialContext context = new MaterialContext();
            var             grammer = context.GrammerTexts.FirstOrDefault(c => c.Id == Id);

            grammer.Name = Name;
            grammer.Text = Text;
            grammer.Date = DateTime.Now;
            context.SaveChanges();
            return(true);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Common gather texture function.
        /// </summary>
        /// <param name="node">The node to look into.</param>
        /// <param name="materialContext">The visitor context.</param>
        /// <returns>A collection of MaterialTextureNode.</returns>
        private IEnumerable <MaterialTextureNode> GatherTextures(IMaterialNode node, MaterialContext materialContext)
        {
            var textureValues = new List <MaterialTextureNode>();

            node.VisitNodes((context, nodeEntry) =>
            {
                var textureValue = nodeEntry.Node as MaterialTextureNode;
                if (textureValue != null)
                {
                    textureValues.Add(textureValue);
                }
            }, materialContext);
            return(textureValues);
        }
        public JsonResult ReplyAnswer(string answerId, string questId)
        {
            int result = 0;

            using (MaterialContext dbcon = new MaterialContext())
            {
                var word = dbcon.Words.FirstOrDefault(s => s.Id == int.Parse(answerId));
                if (word.Word == questId)
                {
                    result = 1;
                }
            }
            return(Json(result));
        }
Exemplo n.º 9
0
        public void BaseOperationTest()
        {
            DbContextOptions <MaterialContext> options = InMemoryDbContextFactory.CreateOptions <MaterialContext>("Material_Base");

            using (MaterialContext content = new MaterialContext(options))
            {
                var obj = content.Materials.SingleOrDefault <Material>(f => f.BomCode == "M1");
                Assert.Null(obj);

                Material m1 = Material.Builder("M1", "N1", 30);
                Material m2 = Material.Builder("M2", "N2", 0);
                Material m3 = Material.Builder("M3", "N3", 20);

                content.Materials.Add(m1);
                content.Materials.Add(m2);
                content.Materials.Add(m3);
                content.Materials.Add(m3);
                var count = content.SaveChanges();

                Assert.Equal(3, count);

                obj = content.Materials.SingleOrDefault <Material>(f => f.BomCode == "M1");
                Assert.NotNull(obj);
                Assert.Equal("M1", obj.BomCode);
                Assert.Equal("N1", obj.BomName);
                Assert.Equal(30, obj.Quantity);

                var objs = content.Materials.Where(f => f.Quantity > 0).ToList <Material>();
                Assert.Equal(2, objs.Count());

                objs = content.Materials.Where(f => f.Quantity / 2 > 10).ToList <Material>();
                Assert.Single(objs);

                objs = content.Materials.Where(f => f.BomName.Contains("N")).ToList <Material>();
                Assert.Equal(3, objs.Count());

                objs = content.Materials.Where(f => f.BomName.Contains("T")).ToList <Material>();
                Assert.Empty(objs);

                objs = content.Materials.Where(f => !f.BomName.Contains("T")).ToList <Material>();
                Assert.Equal(3, objs.Count());

                m2.BomName = "T2";
                content.Materials.Update(m2);
                content.SaveChanges();

                objs = content.Materials.Where(f => !f.BomName.Contains("T")).ToList <Material>();
                Assert.Equal(2, objs.Count());
            }
        }
        private List <Words> LearnWords(string userName)
        {
            List <Words> words   = new List <Words>();
            var          idwords = SqlQueries.ReadWordDatabase(userName);

            using (MaterialContext db = new MaterialContext())
            {
                foreach (var x in idwords)
                {
                    words.Add(db.Words.FirstOrDefault(s => s.Id == x.Id));
                }
            }
            ViewData["LearnUserWords"] = words;
            return(words);
        }
Exemplo n.º 11
0
        public void BeforeTest()
        {
            var builder = new DbContextOptionsBuilder <MaterialContext>();

            builder.EnableSensitiveDataLogging();
            builder.UseInMemoryDatabase("testmaterial");

            var context    = new MaterialContext(builder.Options);
            var repository = new MaterialRepository(context);

            this.controller = new(
                Mock.Of <ILogger <MaterialsController> >(),
                repository);
            Assert.IsNotNull(this.controller);
        }
        public ActionResult AddTestForMaterial(string question, string[] choice, int answer)
        {
            MaterialText materials = Session["TextReading"] as MaterialText;

            if (materials != null)
            {
                using (MaterialContext dbc = new MaterialContext())
                {
                    int testid = dbc.Quizs.Add(new Test.Quiz()
                    {
                        QuizName  = materials.Name,
                        MaterilId = materials.Id
                    }).QuizID;
                    int questionId = dbc.Questions.Add(new Test.Question()
                    {
                        QuestionText = question,
                        QuizID       = testid
                    }).QuestionID;
                    for (int i = 0; i < choice.Length; i++)
                    {
                        dbc.Choices.Add(new Test.Choice()
                        {
                            ChoiceText = choice[i], QuestionID = questionId
                        });
                    }
                    dbc.Answers.Add(new Test.Answer()
                    {
                        AnswerText = choice[answer - 1], QuestionID = questionId
                    });
                    dbc.SaveChanges();
                    ViewBag.ResultAddTest = "Вопрос добавлен";
                    return(View());
                }
            }
            return(View());
        }
 public ActionResult TestsText(int id)
 {
     //MaterialText material = (MaterialText)Session["TextReading"];
     //if (material != null)
     //{
     using (MaterialContext db = new MaterialContext())
     {
         try
         {
             var material = db.Materialtexts.FirstOrDefault(u => u.Id == id);
             var quiz     = db.Quizs.Where(s => s.MaterilId == id).FirstOrDefault();
             ViewBag.Title = quiz.QuizName;
             IQueryable <QuestionModel> questions = db.Questions.Where(q => q.QuizID == quiz.QuizID)
                                                    .Select(q => new QuestionModel
             {
                 QuestionID   = q.QuestionID,
                 QuestionText = q.QuestionText,
                 Choices      = q.Choices.Select(c => new ChoiceModel
                 {
                     ChoiceID   = c.ChoiceID,
                     ChoiceText = c.ChoiceText
                 }).ToList()
             });
             TestTextModel testText = new TestTextModel();
             testText.Text      = material.Text;
             testText.Questions = questions.ToList();
             return(View(testText));
         }
         catch (Exception ex)
         {
             return(View());
         }
     }
     //}
     //return View("Material");
 }
 public MaterialRepository(MaterialContext context)
 {
     _context = context;
 }
Exemplo n.º 15
0
 public CategoryRepository(MaterialContext context)
 {
     _context = context;
 }
        private void MyCommandExecuted(object sender, ExecutedRoutedEventArgs e)
        {
            if (Clipboard.ContainsData(DataFormats.Text))
            {
                try
                {
                    // get all text
                    string data = Clipboard.GetText();
                    // split to lines
                    string[] array = data.Split('\n');
                    // First line is nomer norma
                    WorkContext.Work.Number = array[0];

                    // Second line is Name of process
                    WorkContext.Work.Name = array[1];
                    // Third line is measure of process without "Измеритель"
                    WorkContext.Work.Measure = array[2].Replace("Измеритель", "");
                    // 4, 5, 6, 7, 8, 9, 10 are useless's lines

                    List <PriborContext> priborContexts = new List <PriborContext>();

                    using (var db = new SmetaApplication.DbContexts.SmetaDbAppContext())
                    {
                        foreach (var item in db.Pribors)
                        {
                            priborContexts.Add(new PriborContext(item));
                        }

                        int  i          = 9;
                        bool IsMaterial = true;
                        for (; IsMaterial && i < array.Length; i++)
                        {
                            int      code;
                            string[] split = array[i].Split('\t');
                            // first column is code of pribor, if it isn't pribor, then set IsMaterial = false
                            //MessageBox.Show(array[i]);
                            if (int.TryParse(split[0], out code))
                            {
                                PriborContext priborContext = priborContexts.Find(x => int.Parse(x.Pribor.Code) == code);

                                if (priborContext == null)
                                {
                                    throw new NullReferenceException("Прибор нет: " + split[0] + " : " + split[1]);
                                }

                                priborContext.PriborGroup.Count = 1;
                                WorkContext.PriborContexts.Add(priborContext);

                                // 2 column is name of pribor
                                // 3 column is measure of pribor
                                // begin from 4
                                if (i == 9)
                                {
                                    double time;
                                    bool   IsBegin = true;
                                    if (double.TryParse(split[3].Replace('.', ','), out time))
                                    {
                                        WorkContext.Work.Time1 = time;
                                    }
                                    else
                                    {
                                        IsBegin = false;
                                    }

                                    if (IsBegin && double.TryParse(split[4].Replace('.', ','), out time))
                                    {
                                        WorkContext.Work.Time2 = time;
                                    }
                                    else
                                    {
                                        IsBegin = false;
                                    }

                                    if (IsBegin && double.TryParse(split[5].Replace('.', ','), out time))
                                    {
                                        WorkContext.Work.Time3 = time;
                                    }
                                    else
                                    {
                                        IsBegin = false;
                                    }

                                    if (IsBegin && double.TryParse(split[6].Replace('.', ','), out time))
                                    {
                                        WorkContext.Work.Time4 = time;
                                    }
                                    else
                                    {
                                        IsBegin = false;
                                    }

                                    if (IsBegin && double.TryParse(split[7].Replace('.', ','), out time))
                                    {
                                        WorkContext.Work.Time5 = time;
                                    }
                                    else
                                    {
                                        IsBegin = false;
                                    }
                                }
                            }
                            else
                            {
                                IsMaterial = false;
                            }
                        }

                        List <MaterialContext> materialContexts = new List <MaterialContext>();
                        foreach (var item in db.Materials)
                        {
                            materialContexts.Add(new MaterialContext(item));
                        }

                        // Materials
                        for (; i < array.Length; i++)
                        {
                            int      code;
                            string[] split = array[i].Split('\t');
                            // first column is code of material, if it isn't material, then for does'nt work
                            //MessageBox.Show(array[i]);
                            if (int.TryParse(split[0], out code))
                            {
                                MaterialContext materialContext = materialContexts.Find(x => int.Parse(x.Material.Code) == code);
                                WorkContext.MaterailContexts.Add(materialContext);

                                if (materialContext == null)
                                {
                                    throw new NullReferenceException("Материал нет: " + split[0] + " : " + split[1]);
                                }

                                // 2 column is name of material
                                // 3 column is measure of material
                                // begin from 4

                                double time;
                                bool   IsBegin = true;
                                //MessageBox.Show(split[3]);
                                if (double.TryParse(split[3].Replace('.', ','), out time))
                                {
                                    materialContext.MaterialGroup.Count1 = time;
                                }
                                else
                                {
                                    IsBegin = false;
                                }

                                if (IsBegin && double.TryParse(split[4].Replace('.', ','), out time))
                                {
                                    materialContext.MaterialGroup.Count2 = time;
                                }
                                else
                                {
                                    IsBegin = false;
                                }

                                if (IsBegin && double.TryParse(split[5].Replace('.', ','), out time))
                                {
                                    materialContext.MaterialGroup.Count3 = time;
                                }
                                else
                                {
                                    IsBegin = false;
                                }

                                if (IsBegin && double.TryParse(split[6].Replace('.', ','), out time))
                                {
                                    materialContext.MaterialGroup.Count4 = time;
                                }
                                else
                                {
                                    IsBegin = false;
                                }

                                if (IsBegin && double.TryParse(split[7].Replace('.', ','), out time))
                                {
                                    materialContext.MaterialGroup.Count5 = time;
                                }
                                else
                                {
                                    IsBegin = false;
                                }
                            }
                        }
                    }
                    //WorkContext.Work.PriceMaterial = WorkContext.MaterailContexts.Sum(x => x.Material.Price * x.MaterialGroup.Count1);
                    //WorkContext.Work.PricePribor = WorkContext.PriborContexts.Sum(x => x.Pribor.Price * x.PriborGroup.Count);
                }
                catch (Exception exc)
                {
                    MessageBox.Show("Ошибка формата: " + exc.ToString());
                }
            }
            else
            {
                MessageBox.Show("Ошибка формата");
            }
        }
Exemplo n.º 17
0
 public MaterialController(MaterialContext context)
 {
     _context = context;
 }
Exemplo n.º 18
0
 public ProdutoRepositorio(MaterialContext context)
 {
     _context = context;
 }