Пример #1
0
        public JsonResult UpdateCandidate(CandidateSimpleInfo can)
        {
            long clientId = -1;

            if (!long.TryParse(Session["ClientId"].ToString(), out clientId))
            {
                return(Json(new { rs = -1, msg = "Permission Denied" }, JsonRequestBehavior.AllowGet));
            }
            long recruiterId = -1;

            if (!long.TryParse(Session["RecruiterId"].ToString(), out recruiterId))
            {
                return(Json(new { rs = -1, msg = "Permission Denied" }, JsonRequestBehavior.AllowGet));
            }
            var candidate = db.Candidates.First(s => s.CandidateId == can.CandidateId && s.ClientId == clientId);

            if (candidate == null)
            {
                return(Json(new { rs = -1, msg = "Permission Denied" }, JsonRequestBehavior.AllowGet));
            }
            if (candidate.Status != "Initial")
            {
                return(Json(new { rs = -1, msg = "Error: Can not edit candidate information when they submitted" }, JsonRequestBehavior.AllowGet));
            }
            candidate.FirstName       = can.FirstName;
            candidate.MiddleName      = can.MiddleName;
            candidate.LastName        = can.LastName;
            candidate.Email           = can.Email;
            candidate.PhoneNumber     = can.PhoneNumber;
            candidate.JobTitle        = can.JobTitle;
            candidate.JobLevel        = can.JobLevel;
            db.Entry(candidate).State = EntityState.Modified;
            var r   = db.SaveChanges();
            var log = new ClientLog()
            {
                RecruiterId = candidate.RecruiterId,
                LogType     = "Update Candidate",
                LogTime     = DateTime.Now,
                ClientId    = candidate.ClientId,
                LogContent  = "Update candidate " + can.FirstName + " " + can.MiddleName + " " + can.LastName
            };

            db.ClientLogs.Add(log);
            db.SaveChanges();
            return(Json(new { rs = candidate.CandidateId, msg = r }, JsonRequestBehavior.AllowGet));
        }
Пример #2
0
        public JsonResult CreateCandidate(CandidateSimpleInfo can)
        {
            try
            {
                // return link file of Candidate report
                long recruiterId = -1;
                if (!long.TryParse(Session["RecruiterId"].ToString(), out recruiterId))
                {
                    return(Json(new { rs = -1, msg = "Permission Denied." }, JsonRequestBehavior.AllowGet));
                }
                var recruiter = db.Recruiters.FirstOrDefault(s => s.RecruiterId == recruiterId);
                if (recruiter == null)
                {
                    return(Json(new { rs = -1, msg = "Permission Denied." }, JsonRequestBehavior.AllowGet));
                }

                var userLogin = new UserLogin()
                {
                    UserName          = Util.Helper.getRandomAlphaNumeric(6).ToUpper(),
                    PasswordRaw       = Util.Helper.getRandomAlphaNumeric(8),
                    SecurityStamp     = Util.Helper.getRandomAlphaNumeric(100),
                    Role              = (int)UserRole.CANDIDATE,
                    AccessFailedCount = 0,
                    LockoutEnabled    = true,
                    LockoutDateUtc    = DateTime.UtcNow.AddDays(7)
                };// create user name pass word
                while (db.UserLogins.Any(s => s.UserName == userLogin.UserName))
                {
                    userLogin.UserName = Util.Helper.getRandomAlphaNumeric(6).ToUpper();
                }
                userLogin.PasswordHash = Util.Helper.createMD5Hash(userLogin.PasswordRaw, userLogin.UserName, userLogin.SecurityStamp);

                db.UserLogins.Add(userLogin);
                db.SaveChanges();

                // create candidate
                var candidate = new Candidate()
                {
                    UserLoginId  = userLogin.UserLoginId,
                    FirstName    = can.FirstName,
                    MiddleName   = can.MiddleName,
                    LastName     = can.LastName,
                    Email        = can.Email,
                    PhoneNumber  = can.PhoneNumber,
                    JobTitle     = can.JobTitle,
                    JobLevel     = can.JobLevel,
                    RecruiterId  = recruiter.RecruiterId,
                    ClientId     = recruiter.ClientId,
                    CreatedTime  = DateTime.Now,
                    Status       = "Initial",
                    CompleteTime = DateTime.Now,
                    SpecialistId = -1,
                };
                db.Candidates.Add(candidate);
                db.SaveChanges();
                var log = new ClientLog()
                {
                    RecruiterId = recruiter.RecruiterId,
                    LogType     = "Create Candidate",
                    LogTime     = DateTime.Now,
                    ClientId    = recruiter.ClientId,
                    LogContent  = "Create candidate " + can.FirstName + " " + can.MiddleName + " " + can.LastName
                };
                db.ClientLogs.Add(log);
                db.SaveChanges();
                return(Json(new { rs = candidate.CandidateId, msg = "" }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception e)
            {
                return(Json(new { rs = -1, msg = e.Message }, JsonRequestBehavior.AllowGet));
            }
        }