Example #1
0
        public async Task <ActionResult> RegisterTeacher(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email, Name = model.Name, LastName = model.LastName, PatrName = model.PatrName
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    using (var db = new ATinformContainer())
                    {
                        var newUser = new AtUser {
                            AspNetID = user.Id, Name = user.Name, LastName = user.LastName, PatrName = user.PatrName, Email = user.Email, Role = "teacher"
                        };
                        db.AtUserSet.Add(newUser);
                        db.SaveChanges();
                    };

                    await UserManager.AddToRoleAsync(user.Id, "teacher");

                    //await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);
                    return(RedirectToAction("Index", "Home"));
                }
                AddErrors(result);
            }

            // Появление этого сообщения означает наличие ошибки; повторное отображение формы
            return(View(model));
        }
Example #2
0
 public ActionResult FormGroup(int id)
 {
     using (var db = new ATinformContainer())
     {
         var    groups  = db.GroupSet.Where(elm => elm.Course.Id == id && elm.Started == false).ToList();
         string curUser = User.Identity.GetUserId();
         if (groups.Count == 0)
         {
             var newGroup = new Group {
                 Course = db.CourseSet.Find(id), Started = false, Finished = false
             };
             db.GroupSet.Add(newGroup);
             var newGroupStudent = new GroupStudent {
                 Group = newGroup, Student = db.AtUserSet.Where(elm => elm.AspNetID == curUser).First()
             };
             db.GroupStudentSet.Add(newGroupStudent);
         }
         else
         {
             var newGroupStudent = new GroupStudent {
                 Group = groups.First(), Student = db.AtUserSet.Where(elm => elm.AspNetID == curUser).First()
             };
             db.GroupStudentSet.Add(newGroupStudent);
         }
         db.SaveChanges();
     }
     return(RedirectToAction("Index"));
 }
 public ActionResult PostContent(MyContent newContent)
 {
     using (var db = new ATinformContainer())
     {
         try
         {
             newContent.content.PostedDate = DateTime.Now;
             string curUser = User.Identity.GetUserId();
             newContent.content.AtUser = db.AtUserSet.Where(elm => elm.AspNetID == curUser).First();
             newContent.content.Group  = db.GroupSet.Find(newContent.groupId);
             var sanitizer = new HtmlSanitizer();
             newContent.content.Text = sanitizer.Sanitize(newContent.content.Text);
             db.ContentSet.Add(newContent.content);
             db.SaveChanges();
             foreach (var file in newContent.Uploads)
             {
                 if (file != null)
                 {
                     var newFile = new Attachment {
                         FileName = Path.GetFileName(file.FileName), FilePath = "~/FileBase/", Content = newContent.content
                     };
                     var    path         = Path.Combine(Server.MapPath(newFile.FilePath), newFile.FileName);
                     int    count        = 1;
                     string fileNameOnly = Path.GetFileNameWithoutExtension(path);
                     string extension    = Path.GetExtension(path);
                     while (System.IO.File.Exists(path))
                     {
                         string tempFileName = string.Format("{0}({1})", fileNameOnly, count++);
                         newFile.FileName = tempFileName + extension;
                         path             = Path.Combine(Server.MapPath(newFile.FilePath), newFile.FileName);
                     }
                     file.SaveAs(path);
                     db.AttachmentSet.Add(newFile);
                 }
             }
             db.SaveChanges();
         } catch { }
         int id = newContent.content.Group.Id;
         return(RedirectToAction("/SelectedCourse/" + id));
     }
 }
 public ActionResult FinishGroup(int id)
 {
     using (var db = new ATinformContainer())
     {
         var group = db.GroupSet.Find(id);
         group.FinishDate      = DateTime.Now;
         group.Finished        = true;
         db.Entry(group).State = System.Data.Entity.EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
 }
 public ActionResult StartGroup(int id)
 {
     using (var db = new ATinformContainer())
     {
         string curUser = User.Identity.GetUserId();
         var    group   = db.GroupSet.Find(id);
         group.Curator         = db.AtUserSet.Where(elm => elm.AspNetID == curUser).First();
         group.StartDate       = DateTime.Now;
         group.Started         = true;
         db.Entry(group).State = System.Data.Entity.EntityState.Modified;
         var helloContent = new Content {
             Group = group, PostedDate = DateTime.Now, AtUser = group.Curator, PostTheme = "Приветствуем Вас на нашем курсе!"
         };
         helloContent.Text = "<p>Приветствуем Вас на курсе " + group.Course.Name + "! На данной странице куратор будет публиковать учебные материалы, вебинары и их расписание, а также другие новости, связанные с прохождением курса. Желаем Вам продуктивно провести время!</p><br>С уважением, учебный центр ГК «АТ-информ».";
         db.ContentSet.Add(helloContent);
         db.SaveChanges();
         return(RedirectToAction("SelectedCourse/" + group.Id));
     }
 }