Example #1
0
        /// <summary>
        /// Saves the content of the fileUpload control to the database and file system
        /// as the given type.  The file object is returned on success, else null.
        /// </summary>
        public static File SavePDF(FileUpload fileUpload, FileType fileType)
        {
            if (fileUpload.HasFile)
            {
                if (IsPostedFilePDF(fileUpload.PostedFile))
                {
                    File file = new File();

                    file.FileName = fileUpload.FileName;
                    file.FileType = fileType;

                    using (var ts = new TransactionScope())
                    {
                        bool saveSuccess = FileBLL.MakePersistent(file);

                        // Save is a success if the persistence worked and all validation rules are satisfied
                        if (saveSuccess)
                        {
                            fileUpload.SaveAs(FilePath + file.ID.ToString());

                            ts.CommitTransaction(); //On success we commit

                            return(file);
                        }
                    }
                }
            }

            return(null);
        }
        protected void btnSearchPlanReplace_Click(object sender, EventArgs e)
        {
            Position position = currentPosition;

            File searchPlan = FileBLL.SavePDF(fileSearchPlanReplace, SearchPlanFileType);

            if (searchPlan != null)
            {
                //Delete the old file
                FileBLL.DeletePDF(position.SearchPlanFile);

                //Save the new reference
                using (var ts = new TransactionScope())
                {
                    position.SearchPlanFile = searchPlan;

                    PositionBLL.EnsurePersistent(position);

                    ts.CommitTransaction();
                }
            }
            else
            {
                lblInvalidSearchPlanFileType.Text = " *Job Description Must Be a PDF File";
            }
        }
Example #3
0
        private void createProfileForUser(string email)
        {
            Applicant newUser = ApplicationBLL.GetByEmail(email);

            if (newUser == null)
            {
                Response.Redirect(RecruitmentConfiguration.ErrorPage(RecruitmentConfiguration.ErrorType.AUTH));
                return;
            }

            //Create a blank profile for the logged in user
            Profile blankProfile = new Profile();

            blankProfile.AssociatedApplicant = newUser;

            blankProfile.FirstName = string.Empty;
            blankProfile.LastName  = string.Empty;
            blankProfile.Address1  = string.Empty;
            blankProfile.City      = string.Empty;
            blankProfile.State     = string.Empty;

            blankProfile.LastUpdated = null;

            using (var ts = new TransactionScope())
            {
                ProfileBLL.EnsurePersistent(blankProfile);

                ts.CommitTransaction();
            }
        }
Example #4
0
        public override void LoadData()
        {
            base.LoadData();

            Login login = new Login();

            EntityIdSetter.SetIdOf <string>(login, StaticProperties.TestString);

            //Load in a user
            User user = new User();

            user.FirstName = StaticProperties.TestString;
            user.LastName  = StaticProperties.TestString;
            user.LoginIDs  = new List <Login> {
                login
            };

            login.User = user;

            using (var ts = new TransactionScope())
            {
                UserBLL.EnsurePersistent(user);
                GenericBLL <Login, string> .EnsurePersistent(login, true);

                ts.CommitTransaction();
            }
        }
Example #5
0
        /// <summary>
        /// Sends a message according to the given criteria
        /// </summary>
        /// <returns>true on success</returns>
        public static bool SendMessage(string from, string to, string bcc, string subject, string body)
        {
            try
            {
                MessageGateway.SendMessage(from, to, bcc, subject, body);
            }
            catch
            {
                return(false); //False when message sending doesn't succeed
            }

            //Message is sent, record the event
            using (var ts = new TransactionScope())
            {
                var messageTracking = new MessageTracking
                {
                    To       = to,
                    From     = from,
                    Body     = body,
                    DateSent = DateTime.Now,
                    SentBy   = UserContext.Identity == null ? "N/A" : UserContext.Identity.Name
                };

                MessageTrackingBLL.EnsurePersistent(messageTracking);

                ts.CommitTransaction();
            }

            return(true); //Success
        }
    /// <summary>
    /// Close the position and upload the final recruitment report
    /// </summary>
    protected void ClosePosition(object sender, EventArgs e)
    {
        Position position = CurrentPosition;

        File finalRecruitmentReport = FileBLL.SavePDF(fileFinalRecruitmentReport, FinalRecruitmentReportFileType);

        if (finalRecruitmentReport != null)
        {
            //Delete the old file
            if (position.FinalRecruitmentReportFile != null)
            {
                FileBLL.DeletePDF(position.FinalRecruitmentReportFile);
            }

            //Save the new reference
            using (var ts = new TransactionScope())
            {
                position.FinalRecruitmentReportFile = finalRecruitmentReport;
                position.Closed = true;

                PositionBLL.EnsurePersistent(position);

                ts.CommitTransaction();
            }

            Response.Redirect("ClosePositionSuccess.aspx");
        }
        else
        {
            lblFileError.Text = "Uploaded File Must Be In PDF Format";
        }
    }
        /// <summary>
        /// Sends a unsolicited letter to the selected reference
        /// </summary>
        protected void sendEmail_Click(object sender, EventArgs e)
        {
            Button btnSender = (Button)sender;

            int referenceID = int.Parse(btnSender.CommandArgument);

            Reference currentReference = ReferenceBLL.GetByID(referenceID);

            SmtpClient  client  = new SmtpClient();
            MailMessage message = new MailMessage(WebConfigurationManager.AppSettings["emailFromEmail"],
                                                  currentReference.Email,
                                                  "UC Davis Recruitment Unsolicited Letter Response",
                                                  new TemplateProcessing().ProcessTemplate(currentReference, currentReference.AssociatedApplication, UnsolicitedTemplate.TemplateText, false)
                                                  );

            message.IsBodyHtml = true;
            client.Send(message);

            //Record when the unsolicited email was sent out
            using (var ts = new TransactionScope())
            {
                currentReference.UnsolicitedEmailDate = DateTime.Now;

                ReferenceBLL.EnsurePersistent(currentReference);

                ts.CommitTransaction();
            }

            lblResult.Text = "Email sent successfully";
        }
        public override void OnAuthorization(AuthorizationContext filterContext)
        {
            var orderId = int.Parse((string)filterContext.RouteData.Values["id"]);
            var user    = filterContext.HttpContext.User.Identity.Name;

            bool hasRequestorPermission = false;

            using (var ts = new TransactionScope())
            {
                var permissions = from o in _repositoryFactory.OrderRepository.Queryable
                                  where o.Id == orderId
                                  join p in _repositoryFactory.WorkgroupPermissionRepository.Queryable on o.Workgroup.Id equals p.Workgroup.Id
                                  where p.User.Id == user && p.Role.Id == Role.Codes.Requester
                                  select p;

                hasRequestorPermission = permissions.Any();

                ts.CommitTransaction();
            }

            if (!hasRequestorPermission)
            {
                filterContext.Result = new HttpUnauthorizedResult("You do not have access to copy this order");
            }

            base.OnAuthorization(filterContext);
        }
Example #9
0
        public void UpdateEmail()
        {
            Applicant target = NHibernateHelper.DaoFactory.GetApplicantDao().GetById(StaticProperties.ExistingApplicantID, false);

            string originalEmail = target.Email;

            target.Email = StaticProperties.TestString;

            Assert.IsTrue(ValidateBO <Applicant> .isValid(target)); //make sure the target is valid before saving

            using (var ts = new TransactionScope())
            {
                target = NHibernateHelper.DaoFactory.GetApplicantDao().SaveOrUpdate(target);

                ts.CommitTransaction();
            }

            //Get the target back out of the database
            Applicant targetDB = NHibernateHelper.DaoFactory.GetApplicantDao().GetById(StaticProperties.ExistingApplicantID, false);

            //Make sure the email was changed
            Assert.AreEqual <string>(targetDB.Email, StaticProperties.TestString);

            //Change it back
            targetDB.Email = originalEmail;

            Assert.IsTrue(ValidateBO <Applicant> .isValid(targetDB)); //make sure the target is valid before saving

            using (var ts = new TransactionScope())
            {
                NHibernateHelper.DaoFactory.GetApplicantDao().SaveOrUpdate(targetDB);

                ts.CommitTransaction();
            }
        }
        protected void btnUpdateList_Click(object sender, EventArgs e)
        {
            foreach (GridViewRow row in gViewReferences.Rows)
            {
                if (row.RowType == DataControlRowType.DataRow)
                {
                    //Get the unsolicited check box and then current reference
                    CheckBox cboxUnsolicited = (CheckBox)row.FindControl("chkUnsolicited");

                    int       referenceID      = (int)gViewReferences.DataKeys[row.RowIndex]["id"];
                    Reference currentReference = ReferenceBLL.GetByID(referenceID);

                    //Only save the information if it has changed
                    if (currentReference.UnsolicitedReference != cboxUnsolicited.Checked)
                    {
                        using (var ts = new TransactionScope())
                        {
                            currentReference.UnsolicitedReference = cboxUnsolicited.Checked;

                            ReferenceBLL.EnsurePersistent(currentReference);

                            ts.CommitTransaction();
                        }
                    }
                }
            }

            //Notify the user that the update was successful
            lblResult.Text = "Unsolicited List Updated";
        }
Example #11
0
        private void UploadPublications()
        {
            FileType    publicationsFileType = FileTypeBLL.GetByName(STR_Publication);
            Application application          = selectedApplication;

            File file = FileBLL.SavePDF(fileUpload, publicationsFileType);

            using (var ts = new TransactionScope())
            {
                if (file != null)
                {
                    application.Files.Add(file);

                    ApplicationBLL.EnsurePersistent(application);

                    lblStatus.Text = "File Uploaded Successfully";
                }
                else
                {
                    lblStatus.Text = "File Upload Did Not Succeed: Ensure That File Is A PDF File";
                }

                ts.CommitTransaction();
            }

            rptPublications.DataSource = GetFilesOfType(STR_Publication);
            rptPublications.DataBind();
        }
Example #12
0
        protected void ibtnPublicationsRemoveFile_Click(object sender, EventArgs e)
        {
            int  FileID  = 0;
            bool success = false;

            success = int.TryParse(((ImageButton)sender).CommandArgument, out FileID);

            if (success)
            {
                File fileToDelete = FileBLL.GetByID(FileID);

                using (var ts = new TransactionScope())
                {
                    FileBLL.DeletePDF(fileToDelete);

                    //Update the current application
                    Application application = selectedApplication;

                    application.Files.Remove(fileToDelete);

                    ApplicationBLL.EnsurePersistent(application);

                    ts.CommitTransaction();
                }
            }

            rptPublications.DataSource = GetFilesOfType(STR_Publication);
            rptPublications.DataBind();
        }
Example #13
0
        private void UploadFiles()
        {
            FileType selectedFileType = FileTypeBLL.GetByID(int.Parse(dlistFileTypes.SelectedValue));

            //For all fileTypes except for Publications we should remove existing files
            if (selectedFileType.FileTypeName != STR_Publication && selectedFileType.FileTypeName != STR_LetterOfRec)
            {
                RemoveAllFilesOfType(selectedFileType.FileTypeName);
            }

            File file = FileBLL.SavePDF(fileUpload, selectedFileType);

            using (var ts = new TransactionScope())
            {
                if (file != null)
                {
                    Application application = selectedApplication;

                    application.Files.Add(file);

                    ApplicationBLL.EnsurePersistent(application);

                    lblStatus.Text = "File Uploaded Successfully";
                }
                else
                {
                    lblStatus.Text = "File Upload Did Not Succeed: Ensure That File Is A PDF File";
                }

                ts.CommitTransaction();
            }
        }
        protected void btnUpdateAccess_Click(object sender, EventArgs e)
        {
            foreach (var row in lviewMembers.Items)
            {
                if (row.ItemType == ListViewItemType.DataItem)
                {
                    CheckBox cboxCommittee = row.FindControl(STR_ChkAllowCommittee) as CheckBox;
                    CheckBox cboxFaculty   = row.FindControl(STR_ChkAllowFaculty) as CheckBox;
                    CheckBox cboxReview    = row.FindControl(STR_ChkAllowReview) as CheckBox;

                    //Get the departmental member associated with this row
                    int departmentMemberID  = (int)lviewMembers.DataKeys[row.DataItemIndex]["id"];
                    DepartmentMember member = DepartmentMemberBLL.GetByID(departmentMemberID);

                    using (var ts = new TransactionScope())
                    {
                        DepartmentMemberBLL.UpdateAccess(member, currentPosition, cboxCommittee.Checked, cboxFaculty.Checked, cboxReview.Checked);

                        ts.CommitTransaction();
                    }
                }
            }

            this.bindMembers();

            this.ShowUpdateAcessRegion();

            //Display an update successful message
            lblCommitteeUpdated.Text = "Committee Membership Successfully Updated";
        }
Example #15
0
        public override void LoadData()
        {
            base.LoadData();

            //Add some applications
            Profile profile = ProfileBLL.GetByID(StaticProperties.ExistingProfileID);

            Application application = new Application();

            application.AppliedPosition   = PositionBLL.GetByID(StaticProperties.ExistingPositionID);
            application.AssociatedProfile = profile;
            application.Email             = StaticProperties.ExistingApplicantEmail;

            application.LastUpdated = DateTime.Now;

            profile.Applications = new List <Application> {
                application
            };

            using (var ts = new TransactionScope())
            {
                ApplicationBLL.EnsurePersistent(application);
                ProfileBLL.EnsurePersistent(profile);

                ts.CommitTransaction();
            }
        }
        public override void LoadData()
        {
            base.LoadData();

            //Create a default change tracking insance
            var changeType = new ChangeType {
                Type = StaticProperties.TestString
            };

            var changeTracking = new ChangeTracking
            {
                ChangeDate      = DateTime.Now,
                ObjectChanged   = StaticProperties.TestString,
                ObjectChangedID = StaticProperties.TestString,
                UserName        = StaticProperties.TestString,
                ChangeType      = changeType
            };

            using (var ts = new TransactionScope())
            {
                GenericBLL <ChangeType, int> .EnsurePersistent(changeType);

                GenericBLL <ChangeTracking, int> .EnsurePersistent(changeTracking);

                ts.CommitTransaction();
            }
        }
Example #17
0
        public void SaveDeleteTest()
        {
            CommitteeMember member = new CommitteeMember();

            MemberType mtype = NHibernateHelper.DaoFactory.GetMemberTypeDao().GetById((int)MemberTypes.CommitteeMember, false);

            //member.Email = StaticProperties.TestString;
            //member.UserID = StaticProperties.ExistingUserID;
            member.AssociatedPosition = NHibernateHelper.DaoFactory.GetPositionDao().GetById(StaticProperties.ExistingPositionID, false);
            member.DepartmentMember   = NHibernateHelper.DaoFactory.GetDepartmentMemberDao().GetById(1, false);
            member.MemberType         = mtype;

            //Make sure the file is valid
            Assert.IsTrue(ValidateBO <CommitteeMember> .isValid(member), "CommitteeMember not valid: " + member.getValidationResultsAsString(member));

            Assert.IsTrue(member.IsTransient()); //file is not saved

            using (var ts = new TransactionScope())
            {
                member = NHibernateHelper.DaoFactory.GetCommitteeMemberDao().SaveOrUpdate(member);

                ts.CommitTransaction();
            }

            Assert.IsFalse(member.IsTransient());

            CommitteeMember memberDB = new CommitteeMember();

            //Get a new file using the saved file's ID
            memberDB = NHibernateHelper.DaoFactory.GetCommitteeMemberDao().GetById(member.ID, false);

            //Make sure they are the same
            Assert.AreEqual(member, memberDB);

            this.TestContext.WriteLine("Member Created had ID = {0}", memberDB.ID);

            //Now delete the file
            using (var ts = new TransactionScope())
            {
                NHibernateHelper.DaoFactory.GetCommitteeMemberDao().Delete(member);

                ts.CommitTransaction();
            }

            //Make sure it is deleted
            bool isDeleted = false;

            try
            {
                member = NHibernateHelper.DaoFactory.GetCommitteeMemberDao().GetById(memberDB.ID, false);
                member.IsTransient();
            }
            catch (NHibernate.ObjectNotFoundException)
            {
                isDeleted = true;
            }

            Assert.IsTrue(isDeleted);
        }
 public ActionResult MethodWithoutManualTransactionAttributeAndTransactionScope()
 {
     using (var ts = new TransactionScope())
     {
         ts.CommitTransaction();
     }
     return(Content("String"));
 }
Example #19
0
    private bool UploadReferences(int referenceID, byte[] uploadedFile)
    {
        FileType referenceFileType = daoFactory.GetFileTypeDao().GetFileTypeByName(STR_LetterOfRec);

        Reference selectedReference = daoFactory.GetReferenceDao().GetById(referenceID, false);

        //If there is already a reference file, we need to delete it
        if (selectedReference.ReferenceFile != null)
        {
            using (var ts = new TransactionScope())
            {
                int fileID = selectedReference.ReferenceFile.ID;

                daoFactory.GetFileDao().Delete(selectedReference.ReferenceFile);
                selectedReference.ReferenceFile = null;

                //Delete the file from the file system
                System.IO.FileInfo fileToDelete = new System.IO.FileInfo(FilePath + fileID.ToString());
                fileToDelete.Delete();

                daoFactory.GetReferenceDao().SaveOrUpdate(selectedReference);

                ts.CommitTransaction();
            }
        }

        File file = new File();

        file.FileName = selectedReference.FullName + ".pdf";
        file.FileType = referenceFileType;

        using (var ts = new TransactionScope())
        {
            file = daoFactory.GetFileDao().Save(file);

            ts.CommitTransaction();
        }

        if (ValidateBO <File> .isValid(file))
        {
            SaveReferenceWithWatermark(uploadedFile, file.ID.ToString());

            selectedReference.ReferenceFile = file;

            using (var ts = new TransactionScope())
            {
                daoFactory.GetReferenceDao().SaveOrUpdate(selectedReference);

                ts.CommitTransaction();
            }

            return(true);
        }
        else
        {
            return(false);
        }
    }
Example #20
0
        /// <summary>
        /// Returns a list of user's roles (ignoring workgroup)
        /// </summary>
        /// <remarks>
        /// Used to help determine menu context
        /// </remarks>
        /// <param name="userId"></param>
        /// <returns></returns>
        public static List <string> UserRoles(string userId)
        {
            var repositoryFactory = ServiceLocator.Current.GetInstance <IRepositoryFactory>();

            var context = HttpContext.Current;

            // cached value exists?
            var cacheId = string.Format(Resources.Role_CacheId, userId);
            var cRoles  = (List <string>)context.Session[cacheId];

            if (cRoles != null)
            {
                return(cRoles);
            }

            // no cached values, find the roles
            var roles = new List <string>();

            using (var ts = new TransactionScope())
            {
                var user = repositoryFactory.UserRepository.GetNullableById(userId);

                if (user == null)
                {
                    return(roles);
                }

                // get the admin type roles
                roles.AddRange(user.Roles.Select(a => a.Id).Distinct().ToList());

                // load all the permissions
                var permissions = repositoryFactory.WorkgroupPermissionRepository.Queryable.Where(a => a.User == user).Fetch(a => a.Workgroup).ToList();

                // get the regular roles
                roles.AddRange(permissions.Where(a => !a.Workgroup.Administrative).Select(a => a.Role.Id).Distinct().ToList());

                // has role in an administrative workgroup
                if (permissions.Any(a => a.Workgroup.Administrative))
                {
                    roles.Add(Role.Codes.AdminWorkgroup);
                }

                // is ad hoc account manager, used to give access to ldap search and other ajax functions that are being secured.  They have no other roles in the system
                if (!roles.Any() && repositoryFactory.ApprovalRepository.Queryable.Where(a => a.User == user || a.SecondaryUser == user).Any())
                {
                    roles.Add(Role.Codes.AdhocAccountManager);
                }

                ts.CommitTransaction();
            }

            // save the roles into the cache
            // var expiration = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.AddDays(1).Day);
            context.Session.Add(cacheId, roles); //HEY SCOTT!!! Any issues with this when running on both web and cloud service? !!!

            return(roles);
        }
Example #21
0
        public void SaveDeleteTest()
        {
            CAESDO.Recruitment.Core.Domain.File file = new CAESDO.Recruitment.Core.Domain.File();

            FileType ftype = NHibernateHelper.DaoFactory.GetFileTypeDao().GetById(StaticProperties.ExistingFileTypeID, false);

            file.FileType = ftype;
            file.FileName = StaticProperties.TestString;
            file.Label    = string.Empty;

            //Make sure the file is valid
            Assert.IsTrue(ValidateBO <CAESDO.Recruitment.Core.Domain.File> .isValid(file), "File Not Valid");

            Assert.IsTrue(file.IsTransient()); //file is not saved

            using (var ts = new TransactionScope())
            {
                file = NHibernateHelper.DaoFactory.GetFileDao().SaveOrUpdate(file);

                ts.CommitTransaction();
            }

            Assert.IsFalse(file.IsTransient()); //file should now be saved

            CAESDO.Recruitment.Core.Domain.File fileDB = new CAESDO.Recruitment.Core.Domain.File();

            //Get a new file using the saved file's ID
            fileDB = NHibernateHelper.DaoFactory.GetFileDao().GetById(file.ID, false);

            //Make sure they are the same
            Assert.AreEqual(file, fileDB);

            this.TestContext.WriteLine("File Created had ID = {0}", fileDB.ID);

            //Now delete the file
            using (var ts = new TransactionScope())
            {
                NHibernateHelper.DaoFactory.GetFileDao().Delete(file);

                ts.CommitTransaction();
            }

            //Make sure it is deleted
            bool isDeleted = false;

            try
            {
                file = NHibernateHelper.DaoFactory.GetFileDao().GetById(fileDB.ID, false);
                file.IsTransient();
            }
            catch (NHibernate.ObjectNotFoundException)
            {
                isDeleted = true;
            }

            Assert.IsTrue(isDeleted);
        }
        protected void btnAddMember_Click(object sender, EventArgs e)
        {
            //Create the new department member
            DepartmentMember member = new DepartmentMember();

            member.DepartmentFIS       = STR_FRAC;
            member.FirstName           = txtFName.Text;
            member.LastName            = txtLName.Text;
            member.OtherDepartmentName = string.IsNullOrEmpty(txtDepartment.Text) ? "Other" : txtDepartment.Text;
            member.LoginID             = txtLoginID.Text.ToLower().Trim();

            //Create the membership object
            CommitteeMember committeeAccess = new CommitteeMember();

            committeeAccess.AssociatedPosition = currentPosition;
            committeeAccess.DepartmentMember   = member;

            switch (dlistMemberType.SelectedValue)
            {
            case "Committee":
                committeeAccess.MemberType = MemberTypeBLL.GetByID((int)MemberTypes.CommitteeMember);
                break;

            case "Faculty":
                committeeAccess.MemberType = MemberTypeBLL.GetByID((int)MemberTypes.FacultyMember);
                break;

            case "Review":
                committeeAccess.MemberType = MemberTypeBLL.GetByID((int)MemberTypes.Reviewer);
                break;
            }

            //save the department member and add to the position committee for this position
            using (var ts = new TransactionScope())
            {
                DepartmentMemberBLL.EnsurePersistent(member);

                committeeAccess.DepartmentMember = member;

                currentPosition.CommitteeMembers.Add(committeeAccess);

                Position position = currentPosition;

                PositionBLL.EnsurePersistent(position);

                ts.CommitTransaction();
            }

            //Display an update successful message
            lblCommitteeUpdated.Text = "Committee Membership Successfully Updated";

            //rebind the datagrid
            this.bindMembers();

            this.ShowUpdateAcessRegion();
        }
Example #23
0
        public void SaveDeleteProfile()
        {
            Applicant applicant = NHibernateHelper.DaoFactory.GetApplicantDao().GetById(StaticProperties.ExistingApplicantID, false);

            Profile target = new Profile();

            target.AssociatedApplicant = applicant; //associate with the applicant
            target.Address1            = StaticProperties.TestString;
            target.City      = StaticProperties.TestString;
            target.State     = StaticProperties.TestString;
            target.FirstName = StaticProperties.TestString;
            target.LastName  = StaticProperties.TestString;

            //Validate before saving
            Assert.IsTrue(ValidateBO <Profile> .isValid(target), "Target Profile not valid");

            using (var ts = new TransactionScope())
            {
                target = NHibernateHelper.DaoFactory.GetProfileDao().Save(target); //save the target

                ts.CommitTransaction();
            }

            this.TestContext.WriteLine("Profile created: ID={0}", target.ID);

            Assert.IsNotNull(target);
            Assert.IsFalse(target.IsTransient()); //make sure that target is saved to the database

            Profile targetDB = NHibernateHelper.DaoFactory.GetProfileDao().GetById(target.ID, false);

            Assert.IsNotNull(targetDB);
            Assert.AreEqual <Profile>(target, targetDB);

            //Now delete the new profile
            using (var ts = new TransactionScope())
            {
                NHibernateHelper.DaoFactory.GetProfileDao().Delete(target);

                ts.CommitTransaction();
            }
            //Make sure it is deleted
            bool isDeleted = false;

            try
            {
                targetDB = NHibernateHelper.DaoFactory.GetProfileDao().GetById(target.ID, false);
                targetDB.IsTransient(); //check to see if its in the db
            }
            catch (NHibernate.ObjectNotFoundException)
            {
                isDeleted = true;
            }

            Assert.IsTrue(isDeleted);
        }
Example #24
0
        public void SaveDeleteApplication()
        {
            Application target = new Application();

            target.AppliedPosition   = NHibernateHelper.DaoFactory.GetPositionDao().GetById(StaticProperties.ExistingPositionID, false);
            target.AssociatedProfile = NHibernateHelper.DaoFactory.GetProfileDao().GetById(StaticProperties.ExistingProfileID, false);
            //target.ReferSource = NHibernateHelper.DaoFactory.GetReferSourceDao().GetUniqueByExample(new ReferSource("Internet"));

            target.Email       = StaticProperties.TestString;
            target.LastUpdated = DateTime.Now;
            target.Submitted   = false;

            Assert.IsTrue(ValidateBO <Application> .isValid(target));

            Assert.IsTrue(target.IsTransient());

            using (var ts = new TransactionScope())
            {
                target = NHibernateHelper.DaoFactory.GetApplicationDao().SaveOrUpdate(target);

                ts.CommitTransaction();
            }

            Assert.IsFalse(target.IsTransient());

            Application targetDB = NHibernateHelper.DaoFactory.GetApplicationDao().GetById(target.ID, false);

            Assert.AreEqual <Application>(target, targetDB);

            this.TestContext.WriteLine("Application Created had ID = {0}", target.ID);

            using (var ts = new TransactionScope())
            {
                NHibernateHelper.DaoFactory.GetApplicationDao().Delete(target);

                ts.CommitTransaction();
            }

            //Make sure it is deleted
            bool isDeleted = false;

            try
            {
                target = NHibernateHelper.DaoFactory.GetApplicationDao().GetById(targetDB.ID, false);
                target.IsTransient();
            }
            catch (NHibernate.ObjectNotFoundException)
            {
                isDeleted = true;
            }

            Assert.IsTrue(isDeleted);
        }
        /// <summary>
        /// Send a email from the given positions's HR Rep to the given reference's email account.  On success the reference is marked as being
        /// sent the email so she will not be sent another.  The automated email account is BCC'd for reference.
        /// </summary>
        /// <returns>Returns null on success, else returns the name of the offending reference and applicant</returns>
        private string sendReferenceEmail(Position position, Application application, Reference reference)
        {
            TemplateProcessing template = new TemplateProcessing();

            //Process the template to get the body text of the email
            string bodyText = template.ProcessTemplate(reference, application, position.ReferenceTemplate.TemplateText, true);

            //Exchange Ops is commented out because it will not send HTML emails currently (also needs MSXML2)
            //Now configure the email host
            //CAESDO.ExchangeOps exops = new ExchangeOps();
            //exops.ConfigureServer(WebConfigurationManager.AppSettings["ServerName"], WebConfigurationManager.AppSettings["Protocol"]);
            //exops.ConfigureEmail(WebConfigurationManager.AppSettings["emailDomainUserName"], WebConfigurationManager.AppSettings["emailUserName"], WebConfigurationManager.AppSettings["emailPassword"]);

            System.Net.Mail.SmtpClient mail = new System.Net.Mail.SmtpClient();

            //Try to send the email -- if there are errors, return the email of the offending reference
            try
            {
                System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage(currentPosition.HREmail, reference.Email, "Reference Request for " + application.AssociatedProfile.FullName, bodyText);
                message.Bcc.Add(WebConfigurationManager.AppSettings["AppMailTo"]); //BCC the recruitments email account
                message.IsBodyHtml = true;

                //System.IO.FileStream descriptionStream = new System.IO.FileStream(FilePath + position.DescriptionFile.ID, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read);

                //message.Attachments.Add(new System.Net.Mail.Attachment(descriptionStream, position.DescriptionFile.FileName));

                mail.Send(message);

                //After the message is sent, close the stream.
                //descriptionStream.Close();

                //exops.SendEmail(reference.Email, "Reference Request for Application" + position.PositionTitle, bodyText, WebConfigurationManager.AppSettings["emailFromEmail"]);
            }
            catch (Exception)
            {
                return(string.Format("{0} ({1})", reference.FullName, application.AssociatedProfile.FullName));
            }

            //No errors, so save the fact that we sent an email to the current reference
            using (var ts = new TransactionScope())
            {
                reference.SentEmail = true;
                reference.EmailDate = DateTime.Now;

                ReferenceBLL.EnsurePersistent(reference);

                ts.CommitTransaction();
            }

            return(null);
        }
        public void SaveDeleteTest()
        {
            ChangeTracking tracking = new ChangeTracking();

            ChangeType ctype = NHibernateHelper.DaoFactory.GetChangeTypeDao().GetById((int)ChangeTypes.Update, false);

            tracking.ObjectChanged   = StaticProperties.TestString;
            tracking.ObjectChangedID = StaticProperties.ExistingProfileID.ToString();
            tracking.ChangeType      = ctype;

            Assert.IsTrue(ValidateBO <ChangeTracking> .isValid(tracking), "Tracking Object Not Valid");

            Assert.IsTrue(tracking.IsTransient());

            using (var ts = new TransactionScope())
            {
                tracking = NHibernateHelper.DaoFactory.GetChangeTrackingDao().SaveOrUpdate(tracking);

                ts.CommitTransaction();
            }

            Assert.IsFalse(tracking.IsTransient());

            ChangeTracking trackingDB = NHibernateHelper.DaoFactory.GetChangeTrackingDao().GetById(tracking.ID, false);

            Assert.AreEqual <ChangeTracking>(tracking, trackingDB);

            this.TestContext.WriteLine("Tracking Created had ID = {0}", trackingDB.ID);

            using (var ts = new TransactionScope())
            {
                NHibernateHelper.DaoFactory.GetChangeTrackingDao().Delete(tracking);

                ts.CommitTransaction();
            }

            ////Make sure it is deleted
            bool isDeleted = false;

            try
            {
                tracking = NHibernateHelper.DaoFactory.GetChangeTrackingDao().GetById(trackingDB.ID, false);
                tracking.IsTransient();
            }
            catch (NHibernate.ObjectNotFoundException)
            {
                isDeleted = true;
            }

            Assert.IsTrue(isDeleted);
        }
Example #27
0
        public static void LoadData()
        {
            using (var ts = new TransactionScope())
            {
                LoadLookupTypes();
                LoadDepartments();
                LoadPositions();
                LoadApplicants();
                LoadApplications();
                LoadUser();

                ts.CommitTransaction();
            }
        }
        /// <summary>
        /// Returns immediately if a uniqueID exists for the given reference, else it generates and saves a new one
        /// into the existing reference's record
        /// </summary>
        private void ensureUniqueID(Reference reference)
        {
            if (string.IsNullOrEmpty(reference.UploadID))
            {
                //We don't have an uploadID, so create a new GUID and assign it to the reference
                using (var ts = new TransactionScope())
                {
                    reference.UploadID = Guid.NewGuid().ToString();

                    ReferenceBLL.EnsurePersistent(reference);

                    ts.CommitTransaction();
                }
            }
        }
Example #29
0
 public ActionResult Index()
 {
     using (var scope = new TransactionScope())
     {
         try
         {
             scope.CommitTransaction();
         }
         catch (Exception e)
         {
             scope.RollbackTransaction();
         }
     }
     return(View());
 }
        public void CascadeSaveTest()
        {
            ChangeTracking target = NHibernateHelper.DaoFactory.GetChangeTrackingDao().GetById(StaticProperties.ExistingTrackingID, false);

            Assert.IsFalse(target.IsTransient());

            if (target.ChangedProperties == null)
            {
                target.ChangedProperties = new List <ChangedProperty>();
            }

            int numProperties = target.ChangedProperties.Count;

            //Now we'll add a few new properties to the target
            target.ChangedProperties.Add(new ChangedProperty(StaticProperties.TestString, StaticProperties.TestString, target));
            target.ChangedProperties.Add(new ChangedProperty(StaticProperties.TestString, StaticProperties.TestString, target));

            Assert.AreEqual <int>(numProperties + 2, target.ChangedProperties.Count); //make sure we have two new properties

            using (var ts = new TransactionScope())
            {
                target = NHibernateHelper.DaoFactory.GetChangeTrackingDao().SaveOrUpdate(target);

                ts.CommitTransaction();
            }

            foreach (ChangedProperty prop in target.ChangedProperties)
            {
                this.TestContext.WriteLine("Changed Property ID = {0} created: Property = {1}, new value = {2}", prop.ID, prop.PropertyChanged, prop.PropertyChangedValue);
            }

            Assert.IsFalse(target.IsTransient());

            Assert.AreEqual <int>(numProperties + 2, target.ChangedProperties.Count); //make sure we STILL have two new properties

            //Delete the new properties
            target.ChangedProperties.RemoveAt(target.ChangedProperties.Count - 1);
            target.ChangedProperties.RemoveAt(target.ChangedProperties.Count - 1);

            using (var ts = new TransactionScope())
            {
                target = NHibernateHelper.DaoFactory.GetChangeTrackingDao().SaveOrUpdate(target);

                ts.CommitTransaction();
            }

            Assert.AreEqual <int>(numProperties, target.ChangedProperties.Count); //make sure we are back at the previous number of properties
        }
        public void CanSaveMessageTrackingEntry()
        {
            var tracking = new MessageTracking
                               {
                                   From = StaticProperties.TestString,
                                   To = StaticProperties.TestString,
                                   SentBy = StaticProperties.TestString,
                                   Body = StaticProperties.TestString,
                                   DateSent = DateTime.Now
                               };

            using (var ts = new TransactionScope())
            {
                GenericBLL<MessageTracking, int>.EnsurePersistent(tracking);

                ts.CommitTransaction();
            }
        }
    private bool UploadPublications(int applicationID, byte[] uploadedFile)
    {
        FileType publicationsFileType = daoFactory.GetFileTypeDao().GetFileTypeByName(STR_Publication);
        Application selectedApplication = daoFactory.GetApplicationDao().GetById(applicationID, false);

        File publication = new File();

        publication.FileName = publicationsFileType.FileTypeName + ".pdf";
        publication.FileType = publicationsFileType;

        using (var ts = new TransactionScope())
        {
            publication = daoFactory.GetFileDao().Save(publication);

            ts.CommitTransaction();
        }

        if (ValidateBO<File>.isValid(publication))
        {
            System.IO.File.WriteAllBytes(FilePath + publication.ID.ToString(), uploadedFile);

            selectedApplication.Files.Add(publication);

            using (var ts = new TransactionScope())
            {
                daoFactory.GetApplicationDao().SaveOrUpdate(selectedApplication);

                ts.CommitTransaction();
            }

            return true;
        }
        else
        {
            return false;
        }
    }
    private bool UploadFiles(int applicationID, int fileTypeID, byte[] uploadedFile)
    {
        FileType selectedFileType = daoFactory.GetFileTypeDao().GetById(fileTypeID, false);
        Application selectedApplication = daoFactory.GetApplicationDao().GetById(applicationID, false);

        //For all fileTypes except for Publications we should remove existing files
        if (selectedFileType.FileTypeName != STR_Publication && selectedFileType.FileTypeName != STR_LetterOfRec)
            RemoveAllFilesOfType(selectedApplication, selectedFileType.FileTypeName);

        File file = new File();

        file.FileName = selectedFileType.FileTypeName + ".pdf";
        file.FileType = selectedFileType;

        using (var ts = new TransactionScope())
        {
            file = daoFactory.GetFileDao().Save(file);

            ts.CommitTransaction();
        }

        if (ValidateBO<File>.isValid(file))
        {
            System.IO.File.WriteAllBytes(FilePath + file.ID.ToString(), uploadedFile);

            selectedApplication.Files.Add(file);

            using (var ts = new TransactionScope())
            {
                daoFactory.GetApplicationDao().SaveOrUpdate(selectedApplication);

                ts.CommitTransaction();
            }

            return true;
        }
        else
        {
            return false;
        }
    }
Example #34
0
        public void SaveDeleteProfile()
        {
            Applicant applicant = NHibernateHelper.DaoFactory.GetApplicantDao().GetById(StaticProperties.ExistingApplicantID, false);

            Profile target = new Profile();
            target.AssociatedApplicant = applicant; //associate with the applicant
            target.Address1 = StaticProperties.TestString;
            target.City = StaticProperties.TestString;
            target.State = StaticProperties.TestString;
            target.FirstName = StaticProperties.TestString;
            target.LastName = StaticProperties.TestString;

            //Validate before saving
            Assert.IsTrue(ValidateBO<Profile>.isValid(target), "Target Profile not valid");

            using (var ts = new TransactionScope())
            {
                target = NHibernateHelper.DaoFactory.GetProfileDao().Save(target); //save the target

                ts.CommitTransaction();
            }

            this.TestContext.WriteLine("Profile created: ID={0}", target.ID);

            Assert.IsNotNull(target);
            Assert.IsFalse(target.IsTransient()); //make sure that target is saved to the database

            Profile targetDB = NHibernateHelper.DaoFactory.GetProfileDao().GetById(target.ID, false);

            Assert.IsNotNull(targetDB);
            Assert.AreEqual<Profile>(target, targetDB);

            //Now delete the new profile
            using (var ts = new TransactionScope())
            {
                NHibernateHelper.DaoFactory.GetProfileDao().Delete(target);

                ts.CommitTransaction();
            }
            //Make sure it is deleted
            bool isDeleted = false;

            try
            {
                targetDB = NHibernateHelper.DaoFactory.GetProfileDao().GetById(target.ID, false);
                targetDB.IsTransient(); //check to see if its in the db
            }
            catch (NHibernate.ObjectNotFoundException)
            {
                isDeleted = true;
            }

            Assert.IsTrue(isDeleted);
        }
Example #35
0
        public override void LoadData()
        {
            base.LoadData();

            var application = ApplicationBLL.GetByID(StaticProperties.ExistingApplicationID);

            //Add some applications info
            CurrentPosition currentPosition = new CurrentPosition
                                                  {
                                                      Address1 = StaticProperties.TestString,
                                                      City = StaticProperties.TestString,
                                                      Country = StaticProperties.TestString,
                                                      Department = StaticProperties.TestString,
                                                      Institution = StaticProperties.TestString,
                                                      Title = StaticProperties.TestString,
                                                      Zip = StaticProperties.TestString,
                                                      State = StaticProperties.TestString,
                                                      ApplicationStepType = ApplicationStepType.CurrentPosition,
                                                      AssociatedApplication = application
                                                  };

            Education education = new Education
                                      {
                                          ApplicationStepType = ApplicationStepType.Education,
                                          AssociatedApplication = application,
                                          Date = DateTime.Now,
                                          Discipline = StaticProperties.TestString,
                                          Institution = StaticProperties.TestString
                                      };

            Reference reference = new Reference {AssociatedApplication = application};

            Survey survey = new Survey {AssociatedApplication = application, Other = StaticProperties.TestString};

            File file = new File
                            {
                                FileName = StaticProperties.TestString,
                            };

            FileType fileType = new FileType {ApplicationFile = true, FileTypeName = StaticProperties.TestString};
            file.FileType = fileType;

            using (var ts = new TransactionScope())
            {
                FileTypeBLL.EnsurePersistent(fileType);
                FileBLL.EnsurePersistent(file);

                application.CurrentPositions = new List<CurrentPosition> {currentPosition};
                application.Education = new List<Education> {education};
                application.References = new List<Reference> {reference};
                application.Surveys = new List<Survey> {survey};
                application.Files = new List<File>{file};

                ApplicationBLL.EnsurePersistent(application);

                ts.CommitTransaction();
            }
        }
Example #36
0
        public void SaveDeleteApplication()
        {
            Application target = new Application();

            target.AppliedPosition = NHibernateHelper.DaoFactory.GetPositionDao().GetById(StaticProperties.ExistingPositionID, false);
            target.AssociatedProfile = NHibernateHelper.DaoFactory.GetProfileDao().GetById(StaticProperties.ExistingProfileID, false);
            //target.ReferSource = NHibernateHelper.DaoFactory.GetReferSourceDao().GetUniqueByExample(new ReferSource("Internet"));

            target.Email = StaticProperties.TestString;
            target.LastUpdated = DateTime.Now;
            target.Submitted = false;

            Assert.IsTrue(ValidateBO<Application>.isValid(target));

            Assert.IsTrue(target.IsTransient());

            using (var ts = new TransactionScope())
            {
                target = NHibernateHelper.DaoFactory.GetApplicationDao().SaveOrUpdate(target);

                ts.CommitTransaction();
            }

            Assert.IsFalse(target.IsTransient());

            Application targetDB = NHibernateHelper.DaoFactory.GetApplicationDao().GetById(target.ID, false);

            Assert.AreEqual<Application>(target, targetDB);

            this.TestContext.WriteLine("Application Created had ID = {0}", target.ID);

            using (var ts = new TransactionScope())
            {
                NHibernateHelper.DaoFactory.GetApplicationDao().Delete(target);

                ts.CommitTransaction();
            }

            //Make sure it is deleted
            bool isDeleted = false;

            try
            {
                target = NHibernateHelper.DaoFactory.GetApplicationDao().GetById(targetDB.ID, false);
                target.IsTransient();
            }
            catch (NHibernate.ObjectNotFoundException)
            {
                isDeleted = true;
            }

            Assert.IsTrue(isDeleted);
        }
    /// <summary>
    /// Removes all files of the given type from the current applicaiton.  This removes the files themselves,
    /// the file info entry and the application files link
    /// </summary>
    private void RemoveAllFilesOfType(Application selectedApplication, string fileTypeName)
    {
        List<File> existingFiles = GetFilesOfType(selectedApplication, fileTypeName);

        if (existingFiles.Count != 0)
        {
            using (var ts = new TransactionScope())
            {
                foreach (File existingFile in existingFiles)
                {
                    selectedApplication.Files.Remove(existingFile);
                    daoFactory.GetFileDao().Delete(existingFile);

                    //Delete the file from the file system
                    System.IO.FileInfo file = new System.IO.FileInfo(FilePath + existingFile.ID.ToString());
                    file.Delete();
                }

                daoFactory.GetApplicationDao().SaveOrUpdate(selectedApplication);

                ts.CommitTransaction();
            }
        }
    }
Example #38
0
        public override void LoadData()
        {
            base.LoadData();

            //Add some applications
            Profile profile = ProfileBLL.GetByID(StaticProperties.ExistingProfileID);

            Application application = new Application();
            application.AppliedPosition = PositionBLL.GetByID(StaticProperties.ExistingPositionID);
            application.AssociatedProfile = profile;
            application.Email = StaticProperties.ExistingApplicantEmail;

            application.LastUpdated = DateTime.Now;

            profile.Applications = new List<Application>{application};

            using (var ts = new TransactionScope())
            {
                ApplicationBLL.EnsurePersistent(application);
                ProfileBLL.EnsurePersistent(profile);

                ts.CommitTransaction();
            }
        }
    private bool UploadReferences(int referenceID, byte[] uploadedFile)
    {
        FileType referenceFileType = daoFactory.GetFileTypeDao().GetFileTypeByName(STR_LetterOfRec);

        Reference selectedReference = daoFactory.GetReferenceDao().GetById(referenceID, false);

        //If there is already a reference file, we need to delete it
        if (selectedReference.ReferenceFile != null)
        {
            using (var ts = new TransactionScope())
            {
                int fileID = selectedReference.ReferenceFile.ID;

                daoFactory.GetFileDao().Delete(selectedReference.ReferenceFile);
                selectedReference.ReferenceFile = null;

                //Delete the file from the file system
                System.IO.FileInfo fileToDelete = new System.IO.FileInfo(FilePath + fileID.ToString());
                fileToDelete.Delete();

                daoFactory.GetReferenceDao().SaveOrUpdate(selectedReference);

                ts.CommitTransaction();
            }
        }

        File file = new File();

        file.FileName = selectedReference.FullName + ".pdf";
        file.FileType = referenceFileType;

        using (var ts = new TransactionScope())
        {
            file = daoFactory.GetFileDao().Save(file);

            ts.CommitTransaction();
        }

        if (ValidateBO<File>.isValid(file))
        {
            SaveReferenceWithWatermark(uploadedFile, file.ID.ToString());

            selectedReference.ReferenceFile = file;

            using (var ts = new TransactionScope())
            {
                daoFactory.GetReferenceDao().SaveOrUpdate(selectedReference);

                ts.CommitTransaction();
            }

            return true;
        }
        else
        {
            return false;
        }
    }