Example #1
0
        /// <summary>
        /// Create JobOffer
        /// </summary>
        /// <param name="model">JobOffer DTO</param>
        /// <param name="userId">User ID</param>
        /// <returns>JobOffer DTO</returns>
        public async Task <JobOfferRes> CreateAsync(JobOfferReq model, int userId)
        {
            User user = await _context.Users
                        .Include(us => us.Customer)
                        .ThenInclude(em => em.Group)
                        .FirstOrDefaultAsync(us => us.UserId == userId);

            // create address
            Address address = _addressService.Create(model.Address);

            // create job offer
            JobOffer jobOffer = new JobOffer
            {
                Title       = model.Title,
                Description = model.Description,
                Wage        = model.Wage,
                Spaces      = model.Spaces,
                Start       = model.Start.ToUniversalTime(),
                End         = model.End.ToUniversalTime(),
                Group       = user.Customer.Group,
                Address     = address
            };

            _context.JobOffers.Add(jobOffer);
            await _context.SaveChangesAsync();

            return(new JobOfferRes(jobOffer));
        }
        public async Task <ActionResult <JobOfferRes> > Post([FromBody] JobOfferReq request)
        {
            int userId = int.Parse(HttpContext.User.Identity.Name);

            var response = await _jobOfferService.CreateAsync(request, userId);

            return(StatusCode(201, response));
        }