Beispiel #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            cUV = uvContext.GetByDenomination(Request.Params.Get("uv"));

            var context = new IdentityDb();

            Uploadfile1.Visible = context.GetUserRole(Context.User.Identity.GetUserId()) == CustomRoles.roles.Prof.ToString();

            if (cUV == null)
            {
                Response.Redirect("/Errors/403.aspx");
            }
            // else

            Page.Title           = cUV.Denomination + ": " + cUV.Name;
            LB_Owner.Text        = userContext.GetUsername(cUV.Owner);
            LB_Desc.Text         = cUV.Description;
            Uploadfile1.id       = cUV.IdUv;
            Uploadfile1.fileType = FileType.UV;

            showFileList();
            ShowQuizzesList();
            ShowProjectList();

            // check if owner for edit button
            bool isOwner = Context.User.Identity.GetUserId() == cUV.Owner;

            Button_Update_UV.Visible   = isOwner;
            Button_AddQuizz.Visible    = isOwner;
            Button_Add_Project.Visible = isOwner;
            Button_Add_Teacher.Visible = isOwner;
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                ViewState["RefUrl"] = Request.UrlReferrer.ToString();
            }

            string uvDenom = Request.Params.Get("uv");

            if (uvDenom != null && uvDenom != "")
            {
                cUV = uvContext.GetByDenomination(uvDenom);

                // prevent from executing the following code when a button is clicked on the page (like "save" for example)
                if (!IsPostBack)
                {
                    Denomination.Text = cUV.Denomination;
                    Name.Text         = cUV.Name;
                    Description.Text  = cUV.Description;
                }
            }
        }
Beispiel #3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                ViewState["RefUrl"] = Request.UrlReferrer.ToString();
            }

            string uvDenom = Request.Params.Get("uv");

            if (uvDenom != null && uvDenom != "")
            {
                cUV = uvContext.GetByDenomination(uvDenom);
            }
            else
            {
                Response.Redirect("/Errors/403.aspx");
            }
        }
        protected void UploadButton_Click(object sender, EventArgs e)
        {
            if (FileUploadControl.HasFile)
            {
                UVDb uvs        = new UVDb();
                int  selectedUv = uvs.GetByDenomination(RadioButtonList_ChoixUV.SelectedItem.Value).IdUv;
                System.Diagnostics.Debug.WriteLine(RadioButtonList_ChoixUV.SelectedItem.Value);

                var    manager       = Context.GetOwinContext().GetUserManager <ApplicationUserManager>();
                var    signInManager = Context.GetOwinContext().Get <ApplicationSignInManager>();
                string prenom        = "";
                string nom           = "";
                //string email;
                //string pwd;
                System.IO.StreamReader file;
                try
                {
                    string filename = Path.GetFileName(FileUploadControl.FileName);
                    FileUploadControl.SaveAs(Server.MapPath("~/") + filename);
                    StatusLabel.Text = "Upload status: File uploaded!";
                    string line;
                    file =
                        new System.IO.StreamReader(Server.MapPath("~/") + filename);
                    IdentityDb id = new IdentityDb();
                    //Regex rxc = new Regex(@"^([^.]+)(?=[.])");
                    //Match mc = rxc.Match(filename);
                    //UVDb u = new UVDb();
                    //UV uv = u.GetByDenomination(mc.Value);
                    while ((line = file.ReadLine()) != null)
                    {
                        //continue;
                        Regex           regex = new Regex(@"(?<=;)(\w*)(?=;)");
                        MatchCollection match = regex.Matches(line);
                        if (match.Count != 2)
                        {
                            continue;
                        }
                        int i = 0;
                        foreach (Match m in match)
                        {
                            if (i == 0)
                            {
                                prenom = m.Value;
                            }
                            if (i == 1)
                            {
                                nom = m.Value;
                            }
                            i++;
                        }
                        Regex rx      = new Regex(@"(?:.(?<!;))+$");
                        Match mpwd    = rx.Match(line);
                        Regex rxemail = new Regex(@"^([^;]+)(?=;)");
                        Match memail  = rxemail.Match(line);



                        var user = new ApplicationUser(nom, prenom)
                        {
                            UserName = prenom + " " + nom, Email = memail.Value
                        };
                        user.Role = "Etud";
                        if (id.Users.FirstOrDefault(usr => usr.UserName == user.UserName) == null)
                        {
                            IdentityResult result = manager.Create(user, mpwd.Value);

                            if (result.Succeeded)
                            {
                                id.AddSharedUV(user.Id, selectedUv);
                            }
                            else
                            {
                                ErrorMessage.Text = result.Errors.FirstOrDefault();
                            }
                        }
                        else
                        {
                            ApplicationUser us = id.GetByEmailEager(user.Email);
                            if (!us.HasAccessToUV(selectedUv))
                            {
                                id.AddSharedUV(us.Id, selectedUv);
                            }
                        }
                    }
                    file.Close();
                }
                catch (Exception ex)
                {
                    StatusLabel.Text = "Upload status: The file could not be uploaded. The following error occured: " + ex.Message;
                }
            }
        }