예제 #1
0
        public async Task <IActionResult> Create()
        {
            var user = await _userManager.GetUserAsync(User);

            if (user == null)
            {
                return(Redirect("/Identity/Account/Errors/AccessDenied"));
            }

            if (user.AccountType == 0)
            {
                return(Redirect("/Identity/Account/Manage/Pricing"));
            }

            if (!user.profileConfirmed)
            {
                _baseService.ToastNotify(ToastMessageState.Error, "Грешка", "Моля попълнете личните си данни преди да продължите.", 7000);
                return(Redirect("/Identity/Account/Manage/EditProfile"));
            }
            CreateCompanyInputModel viewModel = new CreateCompanyInputModel();

            viewModel.AllLocations = _locationService.GetAllSelectList();

            return(View(viewModel));
        }
예제 #2
0
        public void Update(CreateCompanyInputModel viewModel, int approved, bool authenticEIK, User user)
        {
            Id = viewModel.Id;

            Guard.Against.NullOrEmpty(viewModel.Title, nameof(viewModel.Title));
            Title = viewModel.Title;

            Guard.Against.NullOrEmpty(viewModel.Email, nameof(viewModel.Email));
            Email = viewModel.Email;

            Guard.Against.NullOrEmpty(viewModel.About, nameof(viewModel.About));
            About = viewModel.About;

            Guard.Against.NullOrEmpty(viewModel.Adress, nameof(viewModel.Adress));
            Adress = viewModel.Adress;

            PhoneNumber = viewModel.PhoneNumber;
            Website     = viewModel.Website;
            Admin1_Id   = viewModel.Admin1_Id;
            Admin2_Id   = viewModel.Admin2_Id;
            Admin3_Id   = viewModel.Admin3_Id;
            Private     = viewModel.Private;
            Logo        = viewModel.Logo == null ? Logo : viewModel.Logo;
            LocationId  = viewModel.LocationId;

            isAuthentic_EIK = authenticEIK;
            PosterId        = user.Id;
            isApproved      = approved;
            Date            = DateTime.Now;
        }
예제 #3
0
        public async Task <string> CreateCompanyAsync(CreateCompanyInputModel inputModel)
        {
            string cloudinaryPicName = inputModel.Name.ToLower();
            string folderName        = "company_images";

            var url = await this.cloudinaryService.UploadPhotoAsync(inputModel.Picture, cloudinaryPicName, folderName);

            var companyPictureId = await this.pictureService.AddPictureAsync(url);

            var company = new Company()
            {
                Name = inputModel.Name, CompanyPictureId = companyPictureId
            };

            await this.companies.AddAsync(company);

            var result = await this.companies.SaveChangesAsync();

            if (result < 0)
            {
                throw new InvalidOperationException("Exception happened in CompanyService while saving the Company in IDeletableEntityRepository<Company>");
            }
            else
            {
                return(company.Id);
            }
        }
예제 #4
0
        public void CreateCompany(CreateCompanyInputModel inputModel)
        {
            var company = Mapper.Map <Company>(inputModel);

            this.companiesRepository.Add(company);
            var result = this.companiesRepository.SaveChangesAsync().GetAwaiter().GetResult();
        }
예제 #5
0
        public async Task <OperationResult> Create(CreateCompanyInputModel viewModel, bool authenticEIK, User user)
        {
            Company company = new Company();

            company.Update(viewModel, 0, authenticEIK, user);

            var entity = await this.companyRepository.AddAsync(company);

            return(entity);
        }
예제 #6
0
        public async Task <OperationResult> Update(CreateCompanyInputModel viewModel, bool authenticEIK, User user)
        {
            var existEntity = companyRepository.GetById(viewModel.Id);

            existEntity.Update(viewModel, existEntity.isApproved, authenticEIK, user);

            var entity = await this.companyRepository.UpdateAsync(existEntity);

            return(entity);
        }
예제 #7
0
        public ActionResult Create(CreateCompanyInputModel inputModel)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(inputModel));
            }

            this.companiesService.CreateCompany(inputModel);

            return(this.RedirectToAction(nameof(this.All)));
        }
예제 #8
0
        public async Task <IActionResult> Create(CreateCompanyInputModel inputModel)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(inputModel));
            }

            var companyId = await this.companyService.CreateCompanyAsync(inputModel);

            return(this.RedirectToAction("RegisterManager", "User", new { companyId }));
        }
예제 #9
0
        public async Task <OperationResult> Update(CreateCompanyInputModel viewModel, bool authenticEIK, User user)
        {
            var existEntity = await companyRepository.GetByIdAsync(viewModel.Id);

            existEntity.Update(viewModel, ApproveType.Waiting, authenticEIK, user);

            this.companyRepository.Update(existEntity);

            var result = await companyRepository.SaveChangesAsync();

            return(result);
        }
예제 #10
0
        public async Task <OperationResult> Create(CreateCompanyInputModel viewModel, bool authenticEIK, User user)
        {
            Company company = new Company();

            company.Update(viewModel, ApproveType.Waiting, authenticEIK, user);

            await this.companyRepository.AddAsync(company);

            var result = await companyRepository.SaveChangesAsync();

            return(result);
        }
        public async Task <IActionResult> Create(CreateCompanyInputModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(model));
            }

            var company = this.mapper.Map <CreditCompany>(model);

            await this.creditCompaniesService.AddCompanyAsync(company);

            return(this.RedirectToAction("All"));
        }
예제 #12
0
        public async Task <IActionResult> CreateCompany(CreateCompanyInputModel inputModel)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View());
            }

            var result = await this.companyService.CreateCompany(inputModel.Name);

            if (!result.Success)
            {
                return(this.View());
            }

            return(this.RedirectToAction(nameof(Details), new { id = result.Data.Id }));
        }
예제 #13
0
        public async Task CreateCompanyAsyncShouldReturnStringIdWhenAddedSuccessfully()
        {
            using (var stream = new MemoryStream())
            {
                IFormFile picture          = new FormFile(stream, 1234, 1234, "name", "fileName");
                var       createInputModel = new CreateCompanyInputModel
                {
                    Name    = "Test",
                    Picture = picture,
                };

                var returnedId = await this.service.CreateCompanyAsync(createInputModel);

                Assert.IsType <string>(returnedId);
            }
        }
예제 #14
0
        public async Task CreateCompanyAsyncShouldAddCompanyToDbSuccessfully()
        {
            using (var stream = new MemoryStream())
            {
                IFormFile picture          = new FormFile(stream, 1234, 1234, "name", "fileName");
                var       createInputModel = new CreateCompanyInputModel
                {
                    Name    = "Test",
                    Picture = picture,
                };

                await this.service.CreateCompanyAsync(createInputModel);
            }

            Assert.Equal(1, await this.dbContext.Companies.CountAsync());
        }
예제 #15
0
        public IActionResult Create(CreateCompanyInputModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(model));
            }

            Company company = new Company
            {
                Name         = model.Name,
                CreationDate = model.CreationDate
            };

            this.companiesService.AddCompany(company);

            return(this.RedirectToAction("Index", "Home"));
        }
예제 #16
0
        public async Task DeleteCompanyAsyncShouldSetIsDeletedToTrue()
        {
            using (var stream = new MemoryStream())
            {
                IFormFile picture          = new FormFile(stream, 1234, 1234, "name", "fileName");
                var       createInputModel = new CreateCompanyInputModel
                {
                    Name    = "Test",
                    Picture = picture,
                };

                var returnedId = await this.service.CreateCompanyAsync(createInputModel);

                await this.service.DeleteCompanyAsync(returnedId);

                Assert.Equal(1, await this.companyRepository.AllWithDeleted().CountAsync());
                Assert.Equal(0, await this.companyRepository.All().CountAsync());
            }
        }
예제 #17
0
        public async Task <IActionResult> Create(CreateCompanyInputModel Input)
        {
            var user = await _userManager.GetUserAsync(User);

            if (user == null)
            {
                return(Redirect("/Identity/Account/Errors/AccessDenied"));
            }


            if (!ModelState.IsValid)
            {
                Input.AllLocations = _locationService.GetAllSelectList();
                return(View(Input));
            }


            if (Input.FormFile != null)
            {
                Input.Logo = await _baseService.UploadImageAsync(Input.FormFile, null, user);
            }

            if (Input.Admin1_Id != null)
            {
                var recruiterUser_1 = await _userManager.FindByNameAsync(Input.Admin1_Id);

                await _userManager.AddToRoleAsync(recruiterUser_1, "Recruiter");

                recruiterUser_1.Role = Roles.Recruiter;
            }

            if (Input.Admin2_Id != null)
            {
                var recruiterUser_2 = await _userManager.FindByNameAsync(Input.Admin2_Id);

                await _userManager.AddToRoleAsync(recruiterUser_2, "Recruiter");

                recruiterUser_2.Role = Roles.Recruiter;
            }

            if (Input.Admin3_Id != null)
            {
                var recruiterUser_3 = await _userManager.FindByNameAsync(Input.Admin3_Id);

                await _userManager.AddToRoleAsync(recruiterUser_3, "Recruiter");

                recruiterUser_3.Role = Roles.Recruiter;
            }

            var result = await _companyService.Create(Input, true, user);


            if (result.Success)
            {
                _baseService.ToastNotify(ToastMessageState.Warning, "Внимание", "Моля изчакайте заявката ви да се прегледа от администратор.", 7000);
                _baseService.ToastNotify(ToastMessageState.Success, "Успешно", "Фирмата ви е добавена.", 5000);
                return(Redirect($"/identity/companies/index"));
            }

            return(View(Input));
        }