示例#1
0
        public ActionResult AddUser(AddUserModel model)
        {
            string userName = User.Identity.Name,
                   roleName = null;

            if (ModelState.IsValid)
            {
                // Attempt to register the user
                MembershipCreateStatus createStatus;
                Membership.CreateUser(model.UserName, model.Password, model.Email, null, null, true, null, out createStatus);

                if (createStatus == MembershipCreateStatus.Success)
                {
                    using (hunterCVEntities context = new hunterCVEntities())
                    {
                        roleName = context.Users.Where(u => u.UserName == userName).Single().Roles.Single().RoleName;

                        var user = context.Users.Single(u => u.UserName == model.UserName);
                        user.ApplicationRole = model.ApplicationRole;
                        context.SaveChanges();
                    }

                    Roles.AddUserToRole(model.UserName, roleName);
                    return(RedirectToAction("Manage", "Account"));
                }
            }

            // If we got this far, something failed, redisplay form
            return(RedirectToAction("Manage", "Account"));
        }
示例#2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="candidate"></param>
        public void Post(IEnumerable <HunterCV.Common.MailTemplate> templates)
        {
            string userName = Membership.GetUser().UserName;

            using (hunterCVEntities context = new hunterCVEntities())
            {
                var role = context.Users.Single(user => user.UserName == userName)
                           .Roles.Single();

                var exists = context.MailTemplates.Where(t => t.RoleId == role.RoleId);

                foreach (MailTemplate tmpl in exists)
                {
                    context.MailTemplates.DeleteObject(tmpl);
                }

                foreach (HunterCV.Common.MailTemplate tmpl in templates)
                {
                    tmpl.RoleId = role.RoleId;
                    MailTemplate target = Mapper.Map <HunterCV.Common.MailTemplate, MailTemplate>(tmpl);

                    context.MailTemplates.AddObject(target);
                }

                context.SaveChanges();
            }
        }
示例#3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="candidate"></param>
        public void Post(HunterCV.Common.Position position)
        {
            string userName = Membership.GetUser().UserName;

            using (hunterCVEntities context = new hunterCVEntities())
            {
                var user = context.Users.Single(u => u.UserName == userName);

                var role = context.Users.Single(uu => uu.UserName == userName)
                           .Roles.Single();

                if (role.LicenseType == "Free")
                {
                    int count = context.Positions.Where(c => c.UserId == user.UserId).Count();

                    if (count >= 1)
                    {
                        throw new HttpResponseException(
                                  new HttpResponseMessage {
                            StatusCode   = HttpStatusCode.Forbidden,
                            Content      = new StringContent("License"),
                            ReasonPhrase = "This license type does not allow the operation"
                        });
                    }
                }

                Position target = Mapper.Map <HunterCV.Common.Position, Position>(position);
                target.User = user;

                context.Positions.AddObject(target);
                context.SaveChanges();
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="candidate"></param>
        public void Delete(string id)
        {
            using (hunterCVEntities context = new hunterCVEntities())
            {
                var candidate = context.Candidates.Where(c => c.CandidateID == new Guid(id)).FirstOrDefault();

                context.Candidates.DeleteObject(candidate);
                context.SaveChanges();
            }
        }
示例#5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="candidate"></param>
        public void Delete(string id)
        {
            using (hunterCVEntities context = new hunterCVEntities())
            {
                var position = context.Positions.Where(c => c.PositionId == new Guid(id)).FirstOrDefault();

                context.Positions.DeleteObject(position);
                context.SaveChanges();
            }
        }
示例#6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="candidate"></param>
        public void Delete(Guid id)
        {
            using (hunterCVEntities context = new hunterCVEntities())
            {
                var resume = context.Previews.Where(c => c.PreviewID == id).FirstOrDefault();

                context.Previews.DeleteObject(resume);
                context.SaveChanges();
            }
        }
示例#7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="candidate"></param>
        public void Delete(int id)
        {
            using (hunterCVEntities context = new hunterCVEntities())
            {
                var resume        = context.Resumes.Where(c => c.ResumeID == id).FirstOrDefault();
                var resumeContent = context.ResumeContents.Where(c => c.ResumeID == id).FirstOrDefault();

                context.Resumes.DeleteObject(resume);
                context.ResumeContents.DeleteObject(resumeContent);
                context.SaveChanges();
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="candidate"></param>
        public void Put(HunterCV.Common.CandidateStatus status)
        {
            string username = Membership.GetUser().UserName;

            using (hunterCVEntities context = new hunterCVEntities())
            {
                var roleEntity = context.Users.Single(user => user.UserName == username)
                                 .Roles.Single();

                roleEntity.CandidatesStatuses = status.Xml;
                context.SaveChanges();
            }
        }
示例#9
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="candidate"></param>
        public void Put(HunterCV.Common.Settings settings)
        {
            string username = Membership.GetUser().UserName;

            using (hunterCVEntities context = new hunterCVEntities())
            {
                var roleEntity = context.Users.Single(user => user.UserName == username)
                                 .Roles.Single();

                roleEntity.Settings = settings.Xml;
                context.SaveChanges();
            }
        }
示例#10
0
        public HttpResponseMessage Put(HunterCV.Common.Resume resume)
        {
            using (hunterCVEntities context = new hunterCVEntities())
            {
                var entity = context.Resumes
                             .Where(p => p.ResumeID == resume.ResumeID).FirstOrDefault();

                entity.Description = resume.Description;
                context.SaveChanges();
            }

            return(Request.CreateResponse(HttpStatusCode.OK));
        }
示例#11
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="candidate"></param>
        public void Put(HunterCV.Common.Area area)
        {
            string username = Membership.GetUser().UserName;

            using (hunterCVEntities context = new hunterCVEntities())
            {
                var role = context.Users.Single(user => user.UserName == username)
                           .Roles.Single();

                role.CandidatesAreas = area.Xml;
                context.SaveChanges();
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="candidate"></param>
        public void Delete(string id)
        {
            string userName = Membership.GetUser().UserName;

            using (hunterCVEntities context = new hunterCVEntities())
            {
                var user      = context.Users.Single(u => u.UserName == userName);
                var candidate = context.Candidates.Where(c => c.CandidateID == new Guid(id)).FirstOrDefault();

                candidate.Starred = null;

                context.SaveChanges();
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="candidate"></param>
        public void Post(HunterCV.Common.Candidate favorite)
        {
            string userName = Membership.GetUser().UserName;

            using (hunterCVEntities context = new hunterCVEntities())
            {
                var user      = context.Users.Single(u => u.UserName == userName);
                var candidate = context.Candidates.Single(c => c.CandidateID == favorite.CandidateID);

                candidate.Starred = favorite.Starred;

                context.SaveChanges();
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="candidate"></param>
        public IEnumerable <HunterCV.Common.Candidate> Put(HunterCV.Common.Candidate candidate)
        {
            string userName = Membership.GetUser().UserName;

            using (hunterCVEntities context = new hunterCVEntities())
            {
                var curruser = context.Users.Single(user => user.UserName == userName);

                if (!candidate.SkipDuplicatesCheck)
                {
                    //check duplicates
                    IEnumerable <Candidate> candidates = context.Candidates.Where(c => c.FirstName.ToLower().Trim() == candidate.FirstName.ToLower().Trim() &&
                                                                                  c.LastName.ToLower().Trim() == candidate.LastName.ToLower().Trim() && c.CandidateID != candidate.CandidateID);

                    if (candidates.Any())
                    {
                        return(candidates.Select(p => Mapper.Map <Candidate, HunterCV.Common.Candidate>(p)).ToList());
                    }
                }

                var entity = Mapper.Map <HunterCV.Common.Candidate, Candidate>(candidate);

                //delete old positions
                context.CandidatePositions.Where(c => c.CandidateId == candidate.CandidateID).Each(d =>
                {
                    context.CandidatePositions.DeleteObject(d);
                });

                entity.UserId = curruser.UserId;

                context.Candidates.Attach(entity);
                context.ObjectStateManager.ChangeObjectState(entity, EntityState.Modified);

                foreach (HunterCV.Common.CandidatePosition position in candidate.CandidatePositions)
                {
                    entity.CandidatePositions.Add(new CandidatePosition
                    {
                        CandidateId             = candidate.CandidateID,
                        PositionId              = position.PositionId,
                        CandidatePositionDate   = position.CandidatePositionDate,
                        CandidatePositionStatus = position.CandidatePositionStatus
                    });
                }

                context.SaveChanges();

                return(null);
            }
        }
示例#15
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="position"></param>
        public void Put(HunterCV.Common.Position position)
        {
            string userName = Membership.GetUser().UserName;

            using (hunterCVEntities context = new hunterCVEntities())
            {
                var curruser = context.Users.Single(user => user.UserName == userName);

                var entity = Mapper.Map <HunterCV.Common.Position, Position>(position);

                entity.UserId = curruser.UserId;

                context.Positions.Attach(entity);

                context.ObjectStateManager.ChangeObjectState(entity, EntityState.Modified);

                context.SaveChanges();
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="candidate"></param>
        public HunterCV.Common.PostCandidateApiResponse Post(HunterCV.Common.Candidate candidate)
        {
            string userName = Membership.GetUser().UserName;

            var response = new HunterCV.Common.PostCandidateApiResponse();

            using (hunterCVEntities context = new hunterCVEntities())
            {
                var user = context.Users.Single(u => u.UserName == userName);
                var role = context.Users.Single(u => u.UserName == userName)
                           .Roles.Single();

                if (role.LicenseType == "Free")
                {
                    int count = context.Candidates.Where(c => c.UserId == user.UserId).Count();

                    if (count >= 10)
                    {
                        throw new HttpResponseException(
                                  new HttpResponseMessage
                        {
                            StatusCode   = HttpStatusCode.Forbidden,
                            Content      = new StringContent("License"),
                            ReasonPhrase = "This license type does not allow the operation"
                        });
                    }
                }

                if (!candidate.SkipDuplicatesCheck)
                {
                    //check duplicates
                    IEnumerable <Candidate> candidates = context.Candidates.Where(c => c.FirstName.ToLower().Trim() == candidate.FirstName.ToLower().Trim() &&
                                                                                  c.LastName.ToLower().Trim() == candidate.LastName.ToLower().Trim());

                    if (candidates.Any())
                    {
                        response.Duplicates = candidates.Select(p => Mapper.Map <Candidate, HunterCV.Common.Candidate>(p)).ToList();
                        return(response);
                    }
                }

                int startIndex = 1000;

                //get start index
                var      docSettings       = XDocument.Parse(role.Settings);
                var      elementsSettings  = docSettings.Root.Elements();
                XElement startIndexElement =
                    (from el in docSettings.Root.Elements("setting")
                     where (string)el.Attribute("title") == "CandidatesStartIndex"
                     select el).FirstOrDefault();

                if (startIndexElement != null)
                {
                    startIndex = (int)startIndexElement.Attribute("value");
                }

                if (context.Candidates.Any())
                {
                    startIndex = context.Candidates.Max(c => c.CandidateNumber).Value + 1;
                }

                candidate.CandidateNumber = startIndex;
                response.NewCandidate     = candidate;

                Candidate target = Mapper.Map <HunterCV.Common.Candidate, Candidate>(candidate);
                target.User = user;
                context.Candidates.AddObject(target);

                //check favorite
                //if (candidate.IsFavorite)
                //{
                //    target.FavoriteUsers.Add(user);
                //}

                context.SaveChanges();

                return(response);
            }
        }
示例#17
0
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                if (Roles.RoleExists(model.Company))
                {
                    ModelState.AddModelError("", "Company name allready exists");
                }
                else
                {
                    // Attempt to register the user
                    MembershipCreateStatus createStatus;
                    Membership.CreateUser(model.UserName, model.Password, model.Email, null, null, true, null, out createStatus);

                    if (createStatus == MembershipCreateStatus.Success)
                    {
                        Roles.CreateRole(model.Company);
                        Roles.AddUserToRole(model.UserName, model.Company);

                        using (hunterCVEntities context = new hunterCVEntities())
                        {
                            var user = context.Users.Single(u => u.UserName == model.UserName);
                            var role = context.Roles.Single(r => r.RoleName == model.Company);

                            //admin user
                            user.ApplicationRole = "A";

                            role.CandidatesCompanies = @"<?xml version=""1.0"" encoding=""utf-8""?><companies><company title=""Coca-Cola, Inc.""></company></companies>";
                            role.CandidatesAreas     = @"<?xml version=""1.0"" encoding=""utf-8"" ?><areas><area title=""Security""></area><area title=""Management""></area><area title=""System""></area><area title=""BI""></area><area title=""Hardware""></area><area title=""QA""><area title=""Automation""></area><area title=""Manual""></area><area title=""Mobile""></area><area title=""Security""></area><area title=""Finance""></area></area><area title=""Developing""><area title=""JAVA""></area><area title=""WEB""></area><area title=""C""></area><area title=""C++""></area></area><area title=""Sales""></area><area title=""Administrator""></area><area title=""IT""></area><area title=""ERP""></area><area title=""Product""></area><area title=""Algorithem""></area><area title=""Embedded""></area><area title=""Electricity Engeneering""></area><area title=""Industrial Management""></area><area title=""Support""></area><area title=""Media""></area><area title=""Analist""></area><area title=""Internet""></area><area title=""UX/UI""></area><area title=""Marketing""></area><area title=""PMO""></area></areas>";
                            role.CandidatesStatuses  = @"<?xml version=""1.0"" encoding=""utf-8""?><statuses>  <status title=""Classification""></status>  <status title=""Interview Process"">  </status>  <status title=""Before Contract Signing"">  </status>  <status title=""Signed""></status></statuses>";
                            role.CandidatesRoles     = @"<?xml version=""1.0"" encoding=""utf-8""?>" +
                                                       @"<roles>" +
                                                       @"<role title=""Team Leader""/>" +
                                                       @"<role title=""Manager""/>" +
                                                       @"<role title=""Director""/>" +
                                                       @"<role title=""VP""/>" +
                                                       @"<role title=""Programmer""/>" +
                                                       @"<role title=""Junior Programmer""/>" +
                                                       @"<role title=""Junior QA""/>" +
                                                       @"<role title=""Student""/>" +
                                                       @"<role title=""QA""/>" +
                                                       @"</roles>";


                            role.PositionsStatuses = @"<?xml version=""1.0"" encoding=""utf-8"" ?><statuses><status title=""Open""></status><status title=""Before Contract Signing""></status><status title=""Manned""></status></statuses>";
                            role.Settings          = @"<?xml version=""1.0"" encoding=""utf-8"" ?><settings><setting title=""PositionsStartIndex"" value=""100"" /><setting title=""CandidatesStartIndex"" value=""1600"" /><setting title=""PhoneFormat"" value=""(999) 000-0000"" /><setting title=""MobileFormat"" value=""(999) 000-0000"" /><setting title=""MSWordPhone2WildCards"" value=""[0-9]{3}-[0-9]{7}"" /><setting title=""MSWordPhone1WildCards"" value=""[0-9]{2}-[0-9]{7}"" /><setting title=""MSWordMobile2WildCards"" value=""[0-9][5][0-9][0-9]{7}"" /><setting title=""MSWordMobile1WildCards"" value=""[0-9][5][0-9]-[0-9]{7}"" /></settings>";
                            role.LicenseType       = "Free";

                            context.SaveChanges();
                        }


                        FormsAuthentication.SetAuthCookie(model.UserName, false /* createPersistentCookie */);
                        return(RedirectToAction("Download", "Subscription"));
                    }
                    else
                    {
                        ModelState.AddModelError("", ErrorCodeToString(createStatus));
                    }
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
示例#18
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="candidate"></param>
        public Task <HttpResponseMessage> Post()
        {
            // Check if the request contains multipart/form-data.
            if (!Request.Content.IsMimeMultipartContent())
            {
                throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
            }

            var  streamProvider = new MultipartMemoryStreamProvider();
            var  query          = Request.GetQueryNameValuePairs();
            Guid previewId      = Guid.Empty;

            if (query != null)
            {
                var matches = query.Where(kv => kv.Key.ToLower() == "previewid");
                if (matches.Count() > 0)
                {
                    previewId = new Guid(matches.First().Value);
                }
            }

            //Ensure.Argument.NotNull(commands, "commands");

            // Read the form data and return an async task.
            var task = Request.Content.ReadAsMultipartAsync(streamProvider).
                       ContinueWith <HttpResponseMessage>(t =>
            {
                if (t.IsFaulted || t.IsCanceled)
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, t.Exception));
                }

                //Select the appropriate content item this assumes only 1 part
                var fileContent = streamProvider.Contents.First();

                string fileName   = fileContent.Headers.ContentDisposition.FileName.Replace("\"", string.Empty);
                Stream fileStream = fileContent.ReadAsStreamAsync().Result;

                string extension   = new FileInfo(fileName).Extension.ToLower();
                string contentType = string.Empty;
                switch (extension)
                {
                case ".pdf":
                    contentType = "application/pdf";
                    break;

                case ".doc":
                    contentType = "application/msword";
                    break;

                case ".docx":
                    contentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
                    break;
                }

                var description = streamProvider.Contents.Last().ReadAsStringAsync().Result;

                using (hunterCVEntities context = new hunterCVEntities())
                {
                    Preview preview     = new Preview();
                    preview.PreviewID   = previewId;
                    preview.FileName    = fileName;
                    preview.ContentType = contentType;
                    preview.FileContent = ReadAllBytes(fileStream);
                    context.AddToPreviews(preview);
                    context.SaveChanges();
                }

                return(Request.CreateResponse(HttpStatusCode.OK));
            });

            return(task);
        }
示例#19
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="candidate"></param>
        public Task <HttpResponseMessage> Post()
        {
            // Check if the request contains multipart/form-data.
            if (!Request.Content.IsMimeMultipartContent())
            {
                throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
            }

            var    streamProvider = new MultipartMemoryStreamProvider();
            var    query          = Request.GetQueryNameValuePairs();
            string candidateId    = string.Empty;

            if (query != null)
            {
                var matches = query.Where(kv => kv.Key.ToLower() == "candidateid");
                if (matches.Count() > 0)
                {
                    candidateId = matches.First().Value;
                }
            }

            //Ensure.Argument.NotNull(commands, "commands");

            // Read the form data and return an async task.
            var task = Request.Content.ReadAsMultipartAsync(streamProvider).
                       ContinueWith <HttpResponseMessage>(t =>
            {
                if (t.IsFaulted || t.IsCanceled)
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, t.Exception));
                }

                if (string.IsNullOrEmpty(candidateId))
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Missing CandidateId parameter"));
                }

                //Select the appropriate content item this assumes only 1 part
                var fileContent = streamProvider.Contents.First();

                string fileName   = fileContent.Headers.ContentDisposition.FileName.Replace("\"", string.Empty);
                Stream fileStream = fileContent.ReadAsStreamAsync().Result;

                var description = streamProvider.Contents.Last().ReadAsStringAsync().Result;

                using (hunterCVEntities context = new hunterCVEntities())
                {
                    Resume resume      = new Resume();
                    resume.FileName    = fileName;
                    resume.Description = description;
                    resume.CandidateID = new Guid(candidateId);
                    context.AddToResumes(resume);
                    context.SaveChanges();

                    ResumeContent content = new ResumeContent();
                    content.ResumeID      = resume.ResumeID;
                    content.FileContent   = ReadAllBytes(fileStream);
                    context.AddToResumeContents(content);
                    context.SaveChanges();
                }

                return(Request.CreateResponse(HttpStatusCode.OK));
            });

            return(task);
        }