Esempio n. 1
0
        public async Task CreatePostAsync(PostRequest input)
        {
            var post    = ObjectMapper.Map <Post>(input);
            var company = await WorkScope.GetAsync <Company>(input.CompanyId);

            int numberPostSameTitle = await WorkScope.GetAll <Post>()
                                      .Where(x => x.Title == input.Title && x.CompanyId == input.CompanyId)
                                      .CountAsync() + 1;

            post.PostUrl = $"{input.Title.RemoveSign4VietnameseString().ToIdentifier()}-{company.CompanyUrl}-{numberPostSameTitle}";
            Guid id = await WorkScope.InsertAndGetIdAsync(post);

            foreach (var item in input.HashtagIds)
            {
                await WorkScope.InsertAsync(new CompanyPostHashtag
                {
                    HashtagId = item,
                    PostId    = id
                });
            }

            var request = new PostSitemap
            {
                Id         = id,
                AgencyName = company.Name,
                IsCreate   = true,
                PostUrl    = post.PostUrl,
                Title      = post.Title
            };

            await SaveSiteMap(request);
        }
Esempio n. 2
0
        public async Task ReadCVAsync(Guid id)
        {
            var cv = await WorkScope.GetAsync <CV>(id);

            cv.IsRead = true;
            await WorkScope.UpdateAsync(cv);
        }
Esempio n. 3
0
        public async Task CreateCVAsync([FromForm] RecruitmentRequest input)
        {
            bool checkExist = await WorkScope.GetAll <CV>().AnyAsync(x => x.PostId == input.PostId &&
                                                                     x.UserId == input.UserId &&
                                                                     input.UserId.HasValue);

            if (checkExist)
            {
                throw new UserFriendlyException("Bạn đã ứng tuyển vị trí này");
            }

            var post = await WorkScope.GetAsync <Post>(input.PostId);

            var cv = ObjectMapper.Map <CV>(input);

            if (input.FileCV?.Length > 0)
            {
                string fileLocation = UploadFiles.CreateFolderIfNotExists(ConstantVariable.RootFolder, $@"{ConstantVariable.UploadFolder}\{ConstantVariable.CV}\{post.PostUrl}");
                string fileName     = await UploadFiles.UploadAsync(fileLocation, input.FileCV);

                cv.Link = $"{ConstantVariable.UploadFolder}/{ConstantVariable.CV}/{post.PostUrl}/{fileName}";
            }

            await WorkScope.InsertAsync(cv);
        }
Esempio n. 4
0
        public async Task <EducationDto> SaveEducation(EducationDto input)
        {
            if ((!WorkScope.GetAll <User, long>().Any(u => u.Id == input.CvemployeeId) || (!input.CvemployeeId.HasValue)))
            {
                throw new UserFriendlyException(ErrorCodes.NotFound.UserNotExist);
            }
            if (AbpSession.UserId.Value != input.CvemployeeId)
            {
                throw new UserFriendlyException(ErrorCodes.Forbidden.AccessOtherProfile);
            }
            int startYear, endYear;

            if (!(int.TryParse(input.StartYear, out startYear) && int.TryParse(input.EndYear, out endYear)))
            {
                throw new UserFriendlyException(ErrorCodes.NotAcceptable.YearIsNotValid);
            }
            if (startYear > endYear)
            {
                throw new UserFriendlyException(ErrorCodes.NotAcceptable.YearOutOfRange);
            }
            if (input.Id <= 0)
            {
                var education = new Educations
                {
                    CvemployeeId       = input.CvemployeeId,
                    SchoolOrCenterName = input.SchoolOrCenterName,
                    DegreeType         = input.DegreeType,
                    Major       = input.Major,
                    StartYear   = input.StartYear,
                    EndYear     = input.EndYear,
                    Description = input.Description,
                    Order       = input.Order
                };
                await WorkScope.GetRepo <Educations, long>().InsertAsync(education);

                return(input);
            }
            else
            {
                var education = await WorkScope.GetAsync <Educations>(input.Id);

                education.CvemployeeId       = input.CvemployeeId;
                education.SchoolOrCenterName = input.SchoolOrCenterName;
                education.DegreeType         = input.DegreeType;
                education.Major       = input.Major;
                education.StartYear   = input.StartYear;
                education.EndYear     = input.EndYear;
                education.Description = input.Description;
                education.Order       = input.Order;
                await WorkScope.GetRepo <Educations, long>().UpdateAsync(education);

                return(input);
            }
        }
Esempio n. 5
0
        public async Task DeleteEducation(long id)
        {
            var edu = await WorkScope.GetAsync <Educations>(id);

            if (edu == null)
            {
                throw new UserFriendlyException(ErrorCodes.NotFound.UserNotExist);
            }
            if (AbpSession.UserId.Value != edu.CvemployeeId)
            {
                throw new UserFriendlyException(ErrorCodes.Forbidden.AccessOtherProfile);
            }
            await WorkScope.DeleteAsync <Educations>(id);
        }
Esempio n. 6
0
        public async Task EditPostAsync(PostRequest input)
        {
            var post = await WorkScope.GetAll <Post>().FirstOrDefaultAsync(x => x.Id == input.Id);

            if (post == default)
            {
                throw new UserFriendlyException("Không tồn tại bài viết");
            }

            ObjectMapper.Map(input, post);
            var company = await WorkScope.GetAsync <Company>(input.CompanyId);

            int numberPostSameTitle = await WorkScope.GetAll <Post>()
                                      .Where(x => x.Title == input.Title && x.CompanyId == input.CompanyId && x.Id != input.Id)
                                      .CountAsync();

            post.PostUrl = numberPostSameTitle > 0
                ? $"{input.Title.RemoveSign4VietnameseString().ToIdentifier()}-{company.CompanyUrl}-{numberPostSameTitle + 1}"
                : $"{input.Title.RemoveSign4VietnameseString().ToIdentifier()}-{company.CompanyUrl}";
            await WorkScope.UpdateAsync(post);

            foreach (var item in input.HashtagIds)
            {
                await WorkScope.InsertAsync(new CompanyPostHashtag
                {
                    HashtagId = item,
                    PostId    = post.Id
                });
            }

            foreach (var item in input.HashtagIdDeletes)
            {
                await WorkScope.DeleteAsync <CompanyPostHashtag>(item);
            }

            var request = new PostSitemap
            {
                Id         = post.Id,
                AgencyName = company.Name,
                IsCreate   = false,
                PostUrl    = post.PostUrl,
                Title      = post.Title
            };

            await SaveSiteMap(request);
        }
Esempio n. 7
0
        public virtual async void Delete(long id)
        {
            var ent = await WorkScope.GetAsync <TEntity>(id);

            await WorkScope.DeleteAsync(ent);
        }