Example #1
0
        private async Task <IActionResult> BuildCreateOrEditDisplayAsync(CreateOrEditResumeViewModel model)
        {
            if (model == null)
            {
                model = new CreateOrEditResumeViewModel()
                {
                    Jobs = new List <SelectListItem>()
                };
            }

            var jobs = await _jobQuerier.GetJobsAsync();

            if (jobs != null)
            {
                model.Jobs = jobs.Select(s => new SelectListItem()
                {
                    Value = s.Id.ToString(),
                    Text  = s.Title
                }).ToList();
            }
            var platforms = await _dictionaryQuerier.GetDictionaryAsync(ResumeDefaults.PlatformType);

            if (platforms != null)
            {
                model.Platforms = platforms.Select(s => new SelectListItem()
                {
                    Value = s.Name,
                    Text  = s.Name
                }).ToList();
            }
            return(View(model));
        }
Example #2
0
        public async Task <IActionResult> Edit(CreateOrEditResumeViewModel model)
        {
            var resume = await _resumeManager.FindByIdAsync(model.Id.Value);

            if (resume == null)
            {
                return(NotFound(model.Id));
            }
            if (ModelState.IsValid)
            {
                try
                {
                    _ = Mapper.Map(model, resume);

                    resume.KeyMaps = new List <ResumeKeywordMap>();
                    if (!string.IsNullOrEmpty(model.Keywords))
                    {
                        var keywords = model.Keywords.Split(' ', StringSplitOptions.RemoveEmptyEntries);
                        foreach (var keyword in keywords)
                        {
                            resume.KeyMaps.Add(new ResumeKeywordMap()
                            {
                                Keyword = keyword,
                                Name    = model.Name
                            });
                        }
                    }
                    resume = await _resumeManager.UpdateAsync(resume, model.IgnoreSimilarity);

                    Notifier.Success("你已成功编辑了一条简历记录。");
                    return(RedirectToAction(nameof(List)));
                }
                catch (Exception ex)
                {
                    Notifier.Warning(ex.Message);
                    model.ResumeCompares = resume.ResumeCompares
                                           .Select(s => new ResumeCompareDto()
                    {
                        Similarity         = s.Similarity,
                        RelationResumeName = s.RelationResumeName,
                        RelationResumeId   = s.RelationResumeId
                    }).ToList();
                }
            }
            return(await BuildCreateOrEditDisplayAsync(model));
        }
Example #3
0
        public async Task <IActionResult> Create(CreateOrEditResumeViewModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var resume = Mapper.Map <Resume>(model);
                    resume.OwnerUserId = UserIdentifier.UserId.Value;
                    await _resumeManager.CreateAsync(resume);

                    Notifier.Success("你已成功创建了一条简历记录。");
                    return(RedirectToAction(nameof(Edit), new { resume.Id }));
                }
                catch (Exception ex)
                {
                    Notifier.Warning(ex.Message);
                }
            }
            return(await BuildCreateOrEditDisplayAsync(model));
        }
Example #4
0
        private async Task <IActionResult> BuildCreateOrEditDisplayAsync(CreateOrEditResumeViewModel model)
        {
            if (model == null)
            {
                model = new CreateOrEditResumeViewModel()
                {
                    Jobs = new List <SelectListItem>()
                };
            }

            var jobs = await _jobQuerier.GetJobsAsync();

            if (jobs != null)
            {
                model.Jobs = jobs.Select(s => new SelectListItem()
                {
                    Value = s.Id.ToString(),
                    Text  = s.Title
                }).ToList();
            }
            var platforms = await _dictionaryQuerier.GetDictionaryAsync(ResumeDefaults.PlatformType);

            if (platforms != null)
            {
                model.Platforms = platforms.Select(s => new SelectListItem()
                {
                    Value = s.Name,
                    Text  = s.Name
                }).ToList();
            }
            var tags = await _dictionaryQuerier.GetDictionaryAsync(ResumeDefaults.TagType);

            if (tags != null)
            {
                model.TagListItems = new List <SelectListItem>();
                foreach (var tag in tags)
                {
                    var item = new SelectListItem()
                    {
                        Value = tag.Name,
                        Text  = tag.Name
                    };
                    if (model.Tags != null && model.Tags.FirstOrDefault(f => f.Value == tag.Name) != null)
                    {
                        item.Selected = true;
                    }
                    model.TagListItems.Add(item);
                }
            }
            var educations = await _dictionaryQuerier.GetDictionaryAsync(ResumeDefaults.EducationType);

            if (educations != null)
            {
                model.Educations = educations.Select(s => new SelectListItem()
                {
                    Value = s.Name,
                    Text  = s.Name
                }).ToList();
            }
            return(View(model));
        }
Example #5
0
        public async Task <IActionResult> Edit(CreateOrEditResumeViewModel model)
        {
            var resume = await _resumeManager.FindByIdAsync(model.Id.Value);

            if (resume == null)
            {
                return(NotFound(model.Id));
            }
            if (ModelState.IsValid)
            {
                try
                {
                    model.Tags = new List <ResumeTagDto>();
                    foreach (string key in Request.Form.Keys)
                    {
                        if (key.StartsWith("Tag.", StringComparison.Ordinal) && Request.Form[key] == "on")
                        {
                            string tagValue = key.Substring("Tag.".Length);
                            model.Tags.Add(new ResumeTagDto()
                            {
                                Value = tagValue
                            });
                        }
                    }

                    _ = Mapper.Map(model, resume);

                    resume.KeyMaps = new List <ResumeKeywordMap>();
                    if (!string.IsNullOrEmpty(model.Keywords))
                    {
                        var keywords = model.Keywords.Split(' ', StringSplitOptions.RemoveEmptyEntries);
                        foreach (var keyword in keywords)
                        {
                            resume.KeyMaps.Add(new ResumeKeywordMap()
                            {
                                Keyword = keyword,
                                Name    = model.Name
                            });
                        }
                    }
                    if (Request.Form.Files != null && Request.Form.Files.Count > 0)
                    {
                        try
                        {
                            var dirPath = $"{_webEnvironment.WebRootPath}/upload/resume-attachments/{DateTime.Now:yyyy-MM-dd}";
                            if (!Directory.Exists(dirPath))
                            {
                                Directory.CreateDirectory(dirPath);
                            }

                            var attachments = new List <ResumeAttachment>();
                            foreach (var file in Request.Form.Files)
                            {
                                var oldFileName       = file.FileName;
                                var fileExtensionName = oldFileName.Substring(oldFileName.LastIndexOf(".") + 1);
                                var fileName          = $"{DateTime.Now:yyyyMMddHHmmssff}{ new Random().Next(10000, 99999) }.{fileExtensionName}";
                                //存储路径
                                var filePath = $"{dirPath}/{fileName}";
                                using (Stream stream = file.OpenReadStream())
                                {
                                    using (FileStream fileStream = new FileStream(filePath, FileMode.Append, FileAccess.Write))
                                    {
                                        int    size   = 1024;
                                        byte[] buffer = new byte[size];
                                        int    length;
                                        while ((length = stream.Read(buffer, 0, size)) > 0)
                                        {
                                            fileStream.Write(buffer);
                                        }
                                    }
                                }
                                attachments.Add(new ResumeAttachment()
                                {
                                    FileName = oldFileName,
                                    FilePath = $"/upload/resume-attachments/{DateTime.Now:yyyy-MM-dd}/{fileName}"
                                });
                            }
                            await _resumeManager.AddAttachmentAsync(resume, attachments);
                        }
                        catch
                        {
                            Notifier.Error("上传附件操作失败。");
                        }
                    }
                    resume = await _resumeManager.UpdateAsync(resume, model.IgnoreSimilarity);

                    Notifier.Success("你已成功编辑了一条简历记录。");
                    return(RedirectToAction(nameof(List)));
                }
                catch (Exception ex)
                {
                    Notifier.Warning(ex.Message);
                    model.ResumeCompares = resume.ResumeCompares
                                           .Select(s => new ResumeCompareDto()
                    {
                        Similarity         = s.Similarity,
                        RelationResumeName = s.RelationResumeName,
                        RelationResumeId   = s.RelationResumeId
                    }).ToList();
                    model.OwnerUserId = resume.OwnerUserId;
                }
            }
            return(await BuildCreateOrEditDisplayAsync(model));
        }