Пример #1
0
        public async Task <IActionResult> PutServicePackages(int id, Packages servicePackages)
        {
            if (id != servicePackages.Id)
            {
                return(BadRequest());
            }

            _context.Entry(servicePackages).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ServicePackagesExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Пример #2
0
        public async Task <IActionResult> PutAcademicInformation(int id, AcademicInformation academicInformation)
        {
            if (id != academicInformation.Id)
            {
                return(BadRequest());
            }

            _context.Entry(academicInformation).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AcademicInformationExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Пример #3
0
        public async Task <IActionResult> PutApplyJob(int id, ApplyJob applyJob)
        {
            if (id != applyJob.Id)
            {
                return(BadRequest());
            }

            _context.Entry(applyJob).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ApplyJobExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Пример #4
0
        public async Task <IActionResult> PutDegreeInfo(int id, DegreeInfo degreeInfo)
        {
            if (id != degreeInfo.Id)
            {
                return(BadRequest());
            }

            _context.Entry(degreeInfo).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!DegreeInfoExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Пример #5
0
        public async Task <IActionResult> PutEmploymentHistory(int id, EmploymentHistory employmentHistory)
        {
            if (id != employmentHistory.Id)
            {
                return(BadRequest());
            }

            _context.Entry(employmentHistory).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!EmploymentHistoryExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Пример #6
0
        public async Task <IActionResult> PutJobSeeker(int id, JobSeekerUser jobSeeker)
        {
            if (id != jobSeeker.Id)
            {
                return(BadRequest());
            }

            _context.Entry(jobSeeker).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!JobSeekerExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Пример #7
0
        public async Task <IActionResult> PutPostModerator(int id, PostModerator postModerator)
        {
            if (id != postModerator.Id)
            {
                return(BadRequest());
            }

            _context.Entry(postModerator).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PostModeratorExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Пример #8
0
        public async Task <IActionResult> PutInvoice(int id, Invoice invoice)
        {
            if (id != invoice.Id)
            {
                return(BadRequest());
            }

            _context.Entry(invoice).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!InvoiceExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Пример #9
0
        public async Task <IActionResult> PutEducationLevel(int id, EducationLevel educationLevel)
        {
            if (id != educationLevel.Id)
            {
                return(BadRequest());
            }

            _context.Entry(educationLevel).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!EducationLevelExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Пример #10
0
        public async Task <ActionResult> PostJob(JobPost postData, string postType)
        {
            // ModelState Error
            if (!ModelState.IsValid)
            {
                var error = new List <string>();
                foreach (var state in ModelState)
                {
                    foreach (var err in state.Value.Errors)
                    {
                        error.Add(err.ToString());
                    }
                }
                return(BadRequest(error));
            }
            // Get Login user Id
            var user = User.FindFirstValue(ClaimTypes.NameIdentifier);

            using (var transaction = await _context.Database.BeginTransactionAsync())
            {
                try
                {
                    JobPost post = postData;
                    post.userId = Guid.Parse(user); // Convert string to Guid
                    // Save as Draft
                    if (postType == "draft")
                    {
                        // Enum postStatus 0==Draft
                        post.PostStatus = Enum.Parse <JobPostStatus>("Draft"); // Convert string to Enum

                        if (postData.Id == 0)
                        {
                            // Save First Time
                            await _context.jobPosts.AddAsync(post);

                            await _context.SaveChangesAsync();
                        }
                        else
                        {
                            // IF exist Update
                            _context.Entry <JobPost>(post).State = EntityState.Modified;
                            await _context.SaveChangesAsync();
                        }

                        await transaction.CommitAsync();

                        return(Created("", post));
                    }
                    // Save as Published
                    else if (postType == "Published")
                    {
                        // Enum postStatus 1==Published
                        post.PostStatus = JobPostStatus.Published;

                        // Exists or Not
                        var package = await _context.servicePackages.FindAsync(post.PackageId);

                        Invoice       checkInvoice       = _context.invoices.Where(i => i.JobPostId == post.Id).AsNoTracking().FirstOrDefault();
                        PostModerator checkPostModeretor = _context.postModerators.Where(p => p.jobPostId == post.Id).AsNoTracking().FirstOrDefault();
                        // .......

                        int invoiceId = 0;
                        if (checkInvoice != null)
                        {
                            invoiceId = checkInvoice.Id;
                        }
                        Invoice invoice = new Invoice
                        {
                            Id            = invoiceId,
                            JobPostId     = post.Id,
                            PackagesId    = package.Id,
                            Quantity      = 1,
                            UnitPrice     = package.Price,
                            PaymentStatus = false,
                            TotalAmount   = package.Price,
                            UserId        = Guid.Parse(user),
                            Date          = DateTime.Now
                        };

                        PostModerator postModerate = new PostModerator
                        {
                            UserId    = Guid.Parse(user),
                            jobPostId = post.Id,
                            Date      = DateTime.Now,
                            Status    = PostStatus.Active
                        };

                        if (post.Id == 0)
                        {
                            await _context.jobPosts.AddAsync(post);

                            await _context.SaveChangesAsync();

                            invoice.JobPostId      = post.Id;
                            postModerate.jobPostId = post.Id;

                            await _context.invoices.AddAsync(invoice);

                            await _context.SaveChangesAsync();

                            // If not exists then create
                            if (checkPostModeretor == null)
                            {
                                await _context.postModerators.AddAsync(postModerate);

                                await _context.SaveChangesAsync();
                            }


                            await transaction.CommitAsync();

                            return(Created("", post));
                        }
                        else
                        {
                            _context.Entry <JobPost>(post).State = EntityState.Modified;

                            // If not exists then create
                            if (checkPostModeretor == null)
                            {
                                await _context.postModerators.AddAsync(postModerate);

                                await _context.SaveChangesAsync();
                            }

                            await _context.SaveChangesAsync();

                            if (checkInvoice == null)
                            {
                                await _context.invoices.AddAsync(invoice);

                                await _context.SaveChangesAsync();
                            }
                            else
                            {
                                _context.Entry <Invoice>(invoice).State = EntityState.Modified;
                            }
                            await transaction.CommitAsync();

                            return(Ok());
                        }
                    }
                }
                catch (Exception ex)
                {
                    await transaction.RollbackAsync();

                    throw ex;
                }
            }
            return(BadRequest());
        }