Exemplo n.º 1
0
 void LoadSitemap(Academic.DbEntities.User.Users user)
 {
     if (SiteMap.CurrentNode != null)
     {
         var list = new List <IdAndName>()
         {
             new IdAndName()
             {
                 Name    = SiteMap.RootNode.Title
                 , Value = SiteMap.RootNode.Url
                 , Void  = true
             },
             new IdAndName()
             {
                 Name    = SiteMap.CurrentNode.ParentNode.Title
                 , Value = SiteMap.CurrentNode.ParentNode.Url
                 , Void  = true
             },
             new IdAndName()
             {
                 Name = user.FullName
                        //Name = SiteMap.CurrentNode.Title
             }
         };
         SiteMapUc.SetData(list);
     }
 }
Exemplo n.º 2
0
        private void SaveFile(int userId, int schoolId, Academic.DbEntities.User.Users savedUser)
        {
            using (var helper = new DbHelper.User())
                using (var fileHelper = new DbHelper.WorkingWithFiles())
                {
                    //var savedUser = helper.AddOrUpdateUser(createdUser, cmbRole.SelectedValue, FileUpload1.PostedFile);

                    //if (savedUser != null)
                    //{
                    //public bool UploadToFolder(HttpPostedFileBase file)
                    //{
                    //    var filename = Path.GetFileName(file.FileName);
                    //    var path = Path.Combine(Server.MapPath("~/Content/Upload"), filename);
                    //    file.SaveAs(path);
                    //    return true;
                    //}

                    //save image
                    //first entry to database : table File --its image
                    if (FileUpload1.HasFile)
                    {
                        var imageFile = FileUpload1.PostedFile;

                        var userPhotoFolder = fileHelper.GetUserPhotoFolder(schoolId);
                        if (userPhotoFolder != null)
                        {
                            var image = new Academic.DbEntities.UserFile()
                            {
                                CreatedBy = userId
                                ,
                                CreatedDate = DateTime.Now
                                ,
                                DisplayName = Path.GetFileName(imageFile.FileName)
                                ,
                                FileDirectory = DbHelper.StaticValues.UserImageDirectory
                                ,
                                FileName =
                                    Guid.NewGuid().ToString() + GetExtension(imageFile.FileName, imageFile.ContentType)
                                ,
                                FileSizeInBytes = imageFile.ContentLength
                                ,
                                FileType = imageFile.ContentType
                                ,
                                IsServerFile = true
                                ,
                                SchoolId = schoolId
                                ,
                                FolderId = userPhotoFolder.Id
                            };
                            using (var fhelper = new DbHelper.WorkingWithFiles())
                            {
                                GetNewGuid(fhelper, image);
                                //TrimFirstLetterFromImageFileName(image);
                                if (trimLoop > 9 || guidLoop > 9)
                                {
                                    //cancel all save
                                }
                                else
                                {
                                    var savedFile = fhelper.AddOrUpdateFile(image);

                                    if (savedFile != null)
                                    {
                                        //save the image with this name
                                        //var filename = Path.GetFileName(file.FileName);
                                        var path = Path.Combine(Server.MapPath(DbHelper.StaticValues.UserImageDirectory),
                                                                image.FileName);
                                        imageFile.SaveAs(path);

                                        //add the image Id to user
                                        helper.UpdateUsersImage(savedUser.Id, savedFile.Id);
                                    }
                                }
                            }
                        }
                        else
                        {
                            lblSaveError.Visible = true;
                            lblSaveError.Text    = "'User Photos' directory not found.";
                        }
                        if (savedUser != null)
                        {
                            ResetTextAndCombos();
                        }
                    }
                    //else
                    //    label.Text = "Error while saving.";
                    //}
                }
        }
Exemplo n.º 3
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            using (var helper = new DbHelper.Student())
            {
                var user = Page.User as CustomPrincipal;
                if (user != null)
                {
                    if (helper.DoesUserNameExist(user.SchoolId, txtUserName.Text))
                    {
                        valiUserName.ErrorMessage = "Username already exits";
                        valiUserName.IsValid      = false;
                    }
                    if (Page.IsValid)
                    {
                        var createdUser = new Academic.DbEntities.User.Users()
                        {
                            CreatedDate = DateTime.Now
                            ,
                            Email = txtEmail.Text
                            ,
                            FirstName = txtFirstName.Text
                            ,
                            LastName = txtLastName.Text
                            ,
                            IsActive = true
                            ,
                            IsDeleted = false
                            ,
                            UserName = txtUserName.Text
                            ,
                            Password = txtPassword.Text
                            ,
                            Phone = txtPhone1.Text
                            ,
                            MiddleName = txtMiddleName.Text
                        };
                        var student = new Academic.DbEntities.Students.Student()
                        {
                            CRN = txtCRN.Text,
                        };

                        createdUser.SchoolId = user.SchoolId;

                        var saved = helper.AddOrUpdateStudent(createdUser, student, ProgramBatchId);

                        if (saved != null)
                        {
                            //file save
                            SaveFile(user.Id, user.SchoolId, saved);

                            Button btn = (Button)sender;
                            if (btn.ID == "btnSaveNAddMore")
                            {
                                //lblSaveStatus.Visible = true;
                                ResetTextAndCombos();
                                //if (SaveClicked != null)
                                //{

                                //    SaveClicked(this, new MessageEventArgs());
                                //}
                            }
                            else if (btn.ID == "btnCancel")
                            {
                                GoBackToProgramBatch();
                                //if (CloseClicked != null)
                                //{
                                //    CloseClicked(this, DbHelper.StaticValues.CancelClickedMessageEventArgs);
                                //}
                            }
                            else
                            {
                                GoBackToProgramBatch();
                                //if (SaveClicked != null)
                                //{
                                //    SaveClicked(this, new MessageEventArgs() { Message = "close" });
                                //}
                            }
                        }
                        else
                        {
                            lblSaveError.Visible = true;
                            lblSaveError.Text    = "Couldn't Save.";
                        }
                    }
                }
            }
        }
Exemplo n.º 4
0
        protected void SaveStudents()
        {
            using (var helper = new DbHelper.Student())
            {
                var user         = Page.User as CustomPrincipal;
                var usersList    = new List <Academic.DbEntities.User.Users>();
                var studentsList = new List <Academic.DbEntities.Students.Student>();

                var stds = Session["studentsList" + PageKey] as List <Academic.DbEntities.Students.Student>;

                //GridView1.DataSource as List<Academic.DbEntities.Students.Student>;


                if (user != null)
                {
                    if (stds != null)
                    {
                        var unVoided = stds.Where(x => !(x.Void ?? false)).ToList();
                        if (!unVoided.Any())
                        {
                            lblSaveError.Visible = true;
                            lblSaveError.Text    = "The list doesn't contain any unique students";
                            return;
                        }
                        foreach (var std in unVoided)
                        {
                            var usr = new Academic.DbEntities.User.Users()
                            {
                                CreatedDate = DateTime.Now,
                                FirstName   = std.Name,
                                IsActive    = true,
                                IsDeleted   = false,
                                UserName    = std.CRN,
                                Password    = std.Name,
                                SchoolId    = user.SchoolId
                            };
                            var student = new Academic.DbEntities.Students.Student()
                            {
                                CRN = std.CRN,
                            };
                            usersList.Add(usr);
                            studentsList.Add(student);
                        }
                        var saved = helper.AddOrUpdateStudents(usersList, studentsList, ProgramBatchId);
                        if (saved)
                        {
                            GoBackToProgramBatch();
                        }
                        else
                        {
                            lblSaveError.Visible = true;
                            lblSaveError.Text    = "Couldn't Save.";
                        }
                    }
                    else
                    {
                        lblSaveError.Visible = true;
                        lblSaveError.Text    = "Couldn't Save. Student data is null. Please try again";
                    }
                }
            }
        }
Exemplo n.º 5
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            var user = Page.User as CustomPrincipal;
            if (user != null)
            {
                using (var fileHelper = new DbHelper.WorkingWithFiles())
                using (var helper = new DbHelper.User())
                {
                    if (helper.DoesUserNameExist(user.SchoolId,UserId, txtUserName.Text))
                    {
                        valiUserName.ErrorMessage = "Username already exists";
                        valiUserName.IsValid = false;
                    }
                    if (Page.IsValid)
                    {
                        var dob = DateTime.MinValue;
                        try
                        {
                            dob = Convert.ToDateTime(txtDOB.Text);
                        }
                        catch
                        {
                        }
                        var date = DateTime.Now.Date;
                        var createdUser = new Academic.DbEntities.User.Users()
                        {
                            SchoolId = user.SchoolId,
                            City = txtCity.Text,
                            Country = txtCountry.Text,
                            CreatedDate = date,
                            Email = txtEmail.Text,
                            FirstName = txtFirstName.Text,
                            MiddleName = txtMidName.Text,
                            LastName = txtLastName.Text,
                            IsActive = true,
                            IsDeleted = false,
                            UserName = txtUserName.Text,
                            Password = txtPassword.Text,
                            Id = UserId,
                            Phone = txtPhone1.Text,
                            //Description = txtDescription.Text,
                        };
                        if (cmbGender.SelectedValue!=""&& cmbGender.SelectedValue!="0")
                        {
                            createdUser.GenderId = Convert.ToInt32(cmbGender.SelectedValue);
                        }
                        if (dob != DateTime.MinValue)
                            createdUser.DOB = dob;

                        var userPhotoDirectory = fileHelper.GetUserPhotoFolder(user.SchoolId);
                        if (userPhotoDirectory != null)
                        {
                            var files = FilesDisplay.GetFiles();
                            UserFile image = null;
                            if (files != null)
                            {
                                if (files.Count >= 1)
                                {

                                    var f = files[0];
                                    //foreach (var f in files)
                                    {
                                        var fileName = Path.GetFileName(f.FilePath);
                                        image = new Academic.DbEntities.UserFile()
                                        {
                                            Id = f.Id,
                                            CreatedBy = user.Id,
                                            CreatedDate = DateTime.Now,
                                            DisplayName = f.FileDisplayName, //Path.GetFileName(imageFile.FileName)
                                            FileDirectory = DbHelper.StaticValues.UserImageDirectory,
                                                //StaticValue.UserImageDirectory
                                            FileName = fileName,
                                                //Guid.NewGuid().ToString() + GetExtension(imageFile.FileName, imageFile.ContentType)
                                            FileSizeInBytes = f.FileSizeInBytes, //imageFile.ContentLength
                                            FileType = f.FileType, //imageFile.ContentType
                                            IconPath = f.IconPath,
                                            SchoolId = user.SchoolId,
                                            IsServerFile = true,
                                            IsConstantAndNotEditable = false,
                                            FolderId = userPhotoDirectory.Id,
                                            //SubjectId = SubjectId,
                                        };
                                        if (f.Id > 0)
                                        {
                                            image.ModifiedBy = user.Id;
                                            image.ModifiedDate = DateTime.Now;
                                        }
                                    }
                                }

                            }

                            //var userRole = new Academic.DbEntities.User.UserRole()
                            //{
                            //    RoleId = Convert.ToInt32(ddlRole.SelectedValue),
                            //    UserId = UserId
                            //};

                            var savedUser = helper.AddOrUpdateUser(createdUser, ddlRole.SelectedValue, image);

                            if (savedUser != null)
                            {
                                if (UserId > 0)
                                {
                                    Response.Redirect("~/Views/User/Detail.aspx?uId=" + UserId);
                                }
                                else
                                {
                                    Response.Redirect("List.aspx");
                                }
                            }
                        }
                        else
                        {
                            //show error of "Folder unable to find"
                            lblSaveStatus.Text = "'User Photos' directory not found.";
                            lblSaveStatus.Visible = true;

                        }


                    }
                }
            }
        }
Exemplo n.º 6
0
        private void SaveFile(int userId, Academic.DbEntities.User.Users savedUser)
        {
            using (var helper = new DbHelper.User())
            {
                //var savedUser = helper.AddOrUpdateUser(createdUser, cmbRole.SelectedValue, FileUpload1.PostedFile);

                //if (savedUser != null)
                //{
                //public bool UploadToFolder(HttpPostedFileBase file)
                //{
                //    var filename = Path.GetFileName(file.FileName);
                //    var path = Path.Combine(Server.MapPath("~/Content/Upload"), filename);
                //    file.SaveAs(path);
                //    return true;
                //}

                //save image
                //first entry to database : table File --its image
                if (FileUpload1.HasFile)
                {
                    var imageFile = FileUpload1.PostedFile;


                    var image = new Academic.DbEntities.UserFile()
                    {
                        CreatedBy = userId
                        ,
                        CreatedDate = DateTime.Now
                        ,
                        DisplayName = Path.GetFileName(imageFile.FileName)
                        ,
                        FileDirectory = DbHelper.StaticValues.UserImageDirectory
                        ,
                        FileName = Guid.NewGuid().ToString() + GetExtension(imageFile.FileName, imageFile.ContentType)
                        ,
                        FileSizeInBytes = imageFile.ContentLength
                        ,
                        FileType = imageFile.ContentType
                        ,
                    };
                    using (var fhelper = new DbHelper.WorkingWithFiles())
                    {
                        GetNewGuid(fhelper, image);
                        //TrimFirstLetterFromImageFileName(image);
                        if (trimLoop > 9 || guidLoop > 9)
                        {
                            //cancel all save
                        }
                        else
                        {
                            var savedFile = fhelper.AddOrUpdateFile(image);

                            if (savedFile != null)
                            {
                                //save the image with this name
                                //var filename = Path.GetFileName(file.FileName);
                                var path = Path.Combine(Server.MapPath(DbHelper.StaticValues.UserImageDirectory),
                                                        image.FileName);
                                imageFile.SaveAs(path);

                                //add the image Id to user
                                helper.UpdateUsersImage(savedUser.Id, savedFile.Id);


                                //    return true;
                            }
                        }
                    }
                }
                //}

                //Label label = (Label)this.Page.FindControl("lblBodyMessage");
                //if (label != null)
                //{
                if (savedUser != null)
                {
                    //label.Text = "Save Successful.";
                    //Page.Response.Redirect("List.aspx");

                    ResetTextAndCombos();
                }
                //else
                //    label.Text = "Error while saving.";
                //}
            }
        }