Example #1
0
 public ActionResult Create(Company company, UserCompanyRef userCompanyRef, string picture)
 {
     if (ModelState.IsValid)
     {
         var result = _companiesService.Create(company, userCompanyRef, User.Identity.GetUserId().ToString(), picture);
         return(RedirectToAction("Index", "UserPanel"));
     }
     return(View(company));
 }
        public async Task <IActionResult> Create(CreateCompanyDto item)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(new ModelStateResult(ModelState)));
            }

            var createCompanyResultDto = await _companiesService.Create(item, UserId);

            return(Ok(createCompanyResultDto));
        }
        public ActionResult Create([Bind("ixCompany,sCompany")] CompaniesPost companies)
        {
            if (ModelState.IsValid)
            {
                companies.UserName = User.Identity.Name;
                _companiesService.Create(companies);
                return(RedirectToAction("Index"));
            }

            return(View(companies));
        }
Example #4
0
 public IActionResult Post([FromBody] CompanyModel companyModel)
 {
     if (companyModel == null)
     {
         return(BadRequest());
     }
     TryValidateModel(companyModel);
     if (this.ModelState.IsValid)
     {
         var company = _companiesService.Create(companyModel);
         return(CreatedAtRoute("GetCustomer", new { controller = "Companies", id = company.Id }, company));
     }
     else
     {
         return(BadRequest());
     }
 }
Example #5
0
        public async Task <Response <SignUpStepDTO <CompanyDTO> > > SignUpCompany(Guid userId, CompanyCreateDTO dto)
        {
            var step = await _repository.GetRegistrationStepByUserId(userId);

            var stepValidate = ValidateStep <CompanyDTO>(step, RegistrationStep.CompanyCreated);

            if (!stepValidate.IsSuccess)
            {
                return(stepValidate);
            }

            if (step.Status == MembershipStatus.Member)
            {
                return(new ForbiddenErrorResponse <SignUpStepDTO <CompanyDTO> >(new Error
                {
                    Code = ErrorCodes.Security.Forbidden,
                    Message = ErrorMessages.Security.Forbidden
                }));
            }

            var company = await _companiesService.Create(userId, dto);

            if (company.IsSuccess)
            {
                step = await _repository.SetRegistrationStep(userId, RegistrationStep.CompanyCreated);
            }


            return(new Response <SignUpStepDTO <CompanyDTO> >
            {
                Data = new SignUpStepDTO <CompanyDTO>
                {
                    Data = company.Data,
                    RegistrationStep = _mapper.Map <UserRegistrationStepModel, UserRegistrationStepDTO>(step)
                }
            });
        }
Example #6
0
        public async Task <Response <CompanyDTO> > CreateCompany(CompanyCreateDTO dto, ClaimsPrincipal claims)
        {
            var result = await _service.Create(claims.GetUserId(), dto);

            return(result);
        }
Example #7
0
        public async Task <IActionResult> Wizard(WizardViewModel model)
        {
            model.Categories = _categoriesService.GetAll();
            model.JobTypes   = _hiretypesService.GetAll();
            model.Companies  = _companiesService.GetByUserId(_currentUser.UserId);

            if (ModelState.IsValid)
            {
                try
                {
                    var companyId = model.CompanyId;
                    if (model.CreateNewCompany)
                    {
                        var company = new Company
                        {
                            Name    = model.CompanyName,
                            Url     = model.CompanyUrl,
                            LogoUrl = model.CompanyLogoUrl,
                            UserId  = _currentUser.UserId,
                            Email   = model.CompanyEmail
                        };

                        if (string.IsNullOrWhiteSpace(company.LogoUrl) ||
                            !company.LogoUrl.StartsWith("https") ||
                            (!company.LogoUrl.EndsWith(".jpg") &&
                             !company.LogoUrl.EndsWith(".jpeg") &&
                             !company.LogoUrl.EndsWith(".png")))
                        {
                            company.LogoUrl = $"{this.Request.Scheme}://{this.Request.Host}{Constants.DefaultLogoUrl}";
                        }
                        _companiesService.Create(company);
                        companyId = company.Id;
                    }

                    if (model.Id.HasValue)
                    {
                        var originalJob = _jobsService.GetById(model.Id.Value);
                        if (originalJob.UserId == _currentUser.UserId)
                        {
                            originalJob.CategoryId  = model.CategoryId;
                            originalJob.HireTypeId  = model.JobTypeId;
                            originalJob.CompanyId   = companyId.Value;
                            originalJob.HowToApply  = model.HowToApply;
                            originalJob.Description = model.Description;
                            originalJob.Title       = model.Title;
                            originalJob.IsRemote    = model.IsRemote;
                            originalJob.IsApproved  = false;
                            if (originalJob.Location.PlaceId != model.LocationPlaceId)
                            {
                                originalJob.Location = new Location
                                {
                                    PlaceId   = model.LocationPlaceId,
                                    Name      = model.LocationName,
                                    Longitude = model.LocationLongitude,
                                    Latitude  = model.LocationLatitude
                                };
                            }
                            var result = _jobsService.Update(originalJob);
                            if (result.Success)
                            {
                                try
                                {
                                    await _slackService.PostJob(originalJob, Url);
                                }
                                catch (Exception ex)
                                {
                                    HttpContext.RiseError(ex);
                                }
                                return(RedirectToAction("Wizard", new { Id = model.Id.Value }).WithSuccess("Posición editada exitosamente"));
                            }

                            return(View(model).WithError(result.Messages));
                        }
                        else
                        {
                            return(RedirectToAction("Index", "Home").WithError("No tienes permiso para editar esta posición"));
                        }
                    }
                    else
                    {
                        var newJob = new Job
                        {
                            CategoryId  = model.CategoryId,
                            HireTypeId  = model.JobTypeId,
                            CompanyId   = companyId.Value,
                            HowToApply  = model.HowToApply,
                            Description = model.Description,
                            Title       = model.Title,
                            IsRemote    = model.IsRemote,
                            Location    = new Location
                            {
                                PlaceId   = model.LocationPlaceId,
                                Name      = model.LocationName,
                                Longitude = model.LocationLongitude,
                                Latitude  = model.LocationLatitude
                            },
                            UserId        = _currentUser.UserId,
                            IsHidden      = false,
                            IsApproved    = false,
                            PublishedDate = DateTime.Now
                        };
                        var result = _jobsService.Create(newJob);
                        if (result.Success)
                        {
                            try
                            {
                                await _slackService.PostJob(newJob, Url).ConfigureAwait(false);
                            }
                            catch (Exception ex)
                            {
                                HttpContext.RiseError(ex);
                            }

                            return(RedirectToAction("Details", new { newJob.Id, isPreview = true }).WithInfo(result.Messages));
                        }

                        throw new Exception(result.Messages);
                    }
                }
                catch (Exception ex)
                {
                    HttpContext.RiseError(ex);
                    return(View(model).WithError(ex.Message));
                }
            }
            return(View(model));
        }
Example #8
0
        public IActionResult Wizard(CompanyViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            try
            {
                if (model.Id > 0)
                {
                    var companyToUpdate = _companiesService.GetById(model.Id);

                    if (companyToUpdate.UserId == _currentUser.UserId)
                    {
                        companyToUpdate.Name    = model.Name;
                        companyToUpdate.Url     = model.Url;
                        companyToUpdate.LogoUrl = model.LogoUrl;
                        companyToUpdate.Email   = model.Email;

                        var result = _companiesService.Update(companyToUpdate);

                        if (result.Success)
                        {
                            return(RedirectToAction("Index", "UserProfile").WithSuccess("Compañia editada exitosamente"));
                        }

                        return(View(model).WithError(result.Messages));
                    }
                    else
                    {
                        return(RedirectToAction("Index", "UserProfile").WithError("No tienes permiso para editar esta Compañia"));
                    }
                }
                else
                {
                    var company = new Company
                    {
                        Name    = model.Name,
                        Url     = model.Url,
                        LogoUrl = model.LogoUrl,
                        UserId  = _currentUser.UserId,
                        Email   = model.Email
                    };

                    if (string.IsNullOrWhiteSpace(company.LogoUrl) ||
                        !company.LogoUrl.StartsWith("https") ||
                        (!company.LogoUrl.EndsWith(".jpg") &&
                         !company.LogoUrl.EndsWith(".jpeg") &&
                         !company.LogoUrl.EndsWith(".png")))
                    {
                        company.LogoUrl = $"{this.Request.Scheme}://{this.Request.Host}{Constants.DefaultLogoUrl}";
                    }

                    var result = _companiesService.Create(company);

                    if (result.Success)
                    {
                        return(RedirectToAction("Index", "UserProfile").WithSuccess("Compañia creada exitosamente"));
                    }

                    return(View(model).WithError(result.Messages));
                }
            }
            catch (Exception ex)
            {
                HttpContext.RiseError(ex);
                return(View(model).WithError(ex.Message));
            }
        }