public string CreateTask(ELTask eLTask, string date, HttpPostedFileBase file)
 {
     if (ModelState.IsValid)
     {
         eLTask.DocumentPath = FileOperations.SaveFile(file, Server, pathToSave, extensions);
         eLTask.AuthorId     = GetUser(eLTask);
         if (string.IsNullOrEmpty(eLTask.Name))
         {
             eLTask.Name = "";
         }
         db.ELTask.Add(eLTask);
         UserELTask userTask = new UserELTask();
         DateTime   tempDate;
         try
         {
             tempDate = Convert.ToDateTime(date);
         }
         catch {
             tempDate = DateTime.Now.AddDays(7);
         }
         userTask.Date   = tempDate;
         userTask.ELTask = eLTask;
         var userIdentity = User.Identity.GetUserId();
         int userId       = db.User.Where(x => x.IdentityId == userIdentity).Select(x => x.UserId).First();
         userTask.UserId = userId;
         db.UserELTask.Add(userTask);
         db.SaveChanges();
     }
     return(eLTask.Name);
 }
        public ActionResult DeleteConfirmed(int id)
        {
            ELTask eLTask = db.ELTask.Find(id);

            FileOperations.DeleteIfExist(Server, eLTask.DocumentPath);
            db.ELTask.Remove(eLTask);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
 public ActionResult Edit([Bind(Include = "TaskId,Name,Description,Text,Group,DocumentPath,Difficult")] ELTask eLTask, HttpPostedFileBase file)
 {
     if (ModelState.IsValid)
     {
         eLTask = EditTaskData(eLTask, file);
         db.Entry(eLTask).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(eLTask));
 }
        private ELTask EditTaskData(ELTask eLTask, HttpPostedFileBase file)
        {
            var path = FileOperations.SaveFile(file, Server, pathToSave, extensions);

            if (!string.IsNullOrWhiteSpace(path))
            {
                FileOperations.DeleteIfExist(Server, eLTask.DocumentPath);
                eLTask.DocumentPath = path;
            }
            eLTask.AuthorId = GetUser(eLTask);
            return(eLTask);
        }
        public ActionResult Create(ELTask eLTask, HttpPostedFileBase file)
        {
            if (ModelState.IsValid)
            {
                eLTask.DocumentPath = FileOperations.SaveFile(file, Server, pathToSave, extensions);
                eLTask.AuthorId     = GetUser(eLTask);
                db.ELTask.Add(eLTask);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(eLTask));
        }
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ELTask eLTask = db.ELTask.Find(id);

            if (eLTask == null)
            {
                return(HttpNotFound());
            }
            return(View(eLTask));
        }
 public string EditTask(ELTask eLTask, HttpPostedFileBase file)
 {
     if (ModelState.IsValid)
     {
         eLTask = EditTaskData(eLTask, file);
         db.Entry(eLTask).State = EntityState.Modified;
         try
         {
             db.SaveChanges();
         }
         catch { }
     }
     return(eLTask.Name);
 }
        public ActionResult EditTaskModal(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ELTask eLTask = db.ELTask.Find(id);

            if (eLTask == null)
            {
                return(HttpNotFound());
            }
            return(PartialView(eLTask));
        }
        private int GetUser(ELTask task)
        {
            int result = 1;

            if (User.IsInRole("moderator"))
            {
                result = db.User.Where(x => x.UserId == 1).Select(x => x.UserId).First();
            }
            else
            {
                var userId = User.Identity.GetUserId();
                result = db.User.Where(x => x.IdentityId == userId).Select(x => x.UserId).First();
            }
            return(result);
        }
 public ActionResult Create([Bind(Include = "GroupId,Name,Difficult,ParentId")] GrammarGroup grammarGroup)
 {
     if (ModelState.IsValid)
     {
         ELTask task = new ELTask()
         {
             AuthorId = 1, Difficult = grammarGroup.Difficult, Group = "Grammar", GrammarGroup = grammarGroup, Name = grammarGroup.Name, Description = "Виконайте граматичну вправу для заданої групи"
         };
         db.ELTask.Add(task);
         db.GrammarGroup.Add(grammarGroup);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.ParentId = new SelectList(db.GrammarGroup, "GroupId", "Name", grammarGroup.ParentId);
     return(View(grammarGroup));
 }
        public ActionResult Create([Bind(Include = "LectionId,Name,OwnerId,LectionType,Description,Editable,ExportOwner,Complexity,ComplexityOrder,LectionPath")] Lection lection, HttpPostedFileBase file)
        {
            if (ModelState.IsValid)
            {
                lection.LectionPath = FileOperations.SaveFile(file, Server, pathToSave, extensions);
                lection.LectionText = new byte[] { };
                ELTask task = new ELTask()
                {
                    AuthorId = 1, Difficult = lection.Complexity, Group = "Lection", Lection = lection, Name = lection.Name, Description = "Прочитайте зазначену лекцію"
                };
                db.ELTask.Add(task);
                db.Lection.Add(lection);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.OwnerId     = new SelectList(db.User, "UserId", "UserId", lection.OwnerId);
            ViewBag.LectionType = new SelectList(db.LectionGroup, "LectionGroupId", "Name", lection.LectionType);
            return(View(lection));
        }
        public ActionResult Create([Bind(Include = "TextId,Name,Text,Words,Difficult")] TextTask textTask)
        {
            if (ModelState.IsValid)
            {
                if (textTask.Words.EndsWith(";"))
                {
                    textTask.Words = textTask.Words.TrimEnd(';');
                }
                textTask.AuthorId = 1;
                ELTask task = new ELTask()
                {
                    AuthorId = 1, Difficult = textTask.Difficult, Group = "TextTask", TextTask = textTask, Name = textTask.Name, Description = "Прочитайте текст та вставте в проміжки слова"
                };
                db.ELTask.Add(task);
                db.TextTask.Add(textTask);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(textTask));
        }
        public ActionResult Create([Bind(Include = "TestId,Name,OwnerId,Difficult,TaskCount,TestType,Editable,ExportOwner,Time,Text")] Test test, HttpPostedFileBase file, HttpPostedFileBase testText)
        {
            if (ModelState.IsValid)
            {
                test.Voice = FileOperations.SaveFile(file, Server, pathToSave, extensions);
                ELTask task = new ELTask()
                {
                    AuthorId = 1, Difficult = test.Difficult, Group = "Test", Test = test, Name = test.Name, Description = "Пройдіть заданий тест"
                };
                if (testText != null && testText.ContentLength > 0)
                {
                    CreateTestFromFile(testText, test);
                }
                db.ELTask.Add(task);
                db.Test.Add(test);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.OwnerId  = new SelectList(db.User, "UserId", "UserId", test.OwnerId);
            ViewBag.TestType = new SelectList(db.TestGroup, "TestGroupId", "Name", test.TestType);
            return(View(test));
        }