Beispiel #1
0
        public async Task <CompanyViewModel> Add(string companyName)
        {
            var model = new CompanyViewModel();

            await _service.AddAsync(new Company { CompanyName = companyName });

            var companies = await _service.GetAllAsync();

            // Geçici olarak yazıldı düzeltilecek
            List <CompanyDto> companyDtos = new List <CompanyDto>();;

            foreach (var item in companies)
            {
                companyDtos.Add(new CompanyDto {
                    CompanyName = item.CompanyName, Id = item.Id
                });
            }

            model.Companies = companyDtos;

            model.ResultModel.Success = true;
            model.ResultModel.Message = $"Şirket Başarılı bir şekilde eklendi.";

            return(model);
        }
        public async Task <ActionResult> Add(InterviewDTO interviewDTO)
        {
            interviewDTO.SalesPerson = await _salesPersonService.GetByNameAndEmailAsync(interviewDTO.SalesPerson);

            var company = await _companyService.GetByNameAsync(interviewDTO.Company.Name);

            if (company == null)
            {
                company = await _companyService.AddAsync(interviewDTO.Company, true);
            }
            interviewDTO.Company = company;

            var interviewer = await _interviewerService.GetByNameAndEmailAsync(interviewDTO.Interviewer);

            if (interviewer == null)
            {
                interviewDTO.Interviewer.Company = company;
                interviewer = await _interviewerService.AddAsync(interviewDTO.Interviewer);
            }
            interviewDTO.Interviewer = interviewer;
            var interview = await _interviewService.AddAsync(interviewDTO);

            foreach (var fairId in interviewDTO.FairIds)
            {
                await _interviewFairService.AddAsync(new InterviewFairDTO
                {
                    Name      = "GörüşmeKaydıFuar" + fairId,
                    Interview = interview,
                    Company   = interviewDTO.Company,
                    Fair      = _fairService.Get(Guid.Parse(fairId))
                });
            }
            return(Ok());
        }
        public async Task <ActionResult <CompanyDto> > Add(CompanyForAddDto companyForAdd)
        {
            Company company = _mapper.Map <Company>(companyForAdd);
            await _companyService.AddAsync(company);

            return(CreatedAtAction(nameof(GetById), new { id = company.CompanyId }, _mapper.Map <CompanyDto>(company)));
        }
        public async Task <ActionResult <Company> > Post(Company company)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            await _companyService.AddAsync(company);

            return(CreatedAtAction(nameof(Get), new { id = company.Id }, company));
        }
Beispiel #5
0
        public async Task <IActionResult> Post([FromBody] Company company)
        {
            if (company == null || company.Id != 0)
            {
                return(BadRequest());
            }

            await _companyService.AddAsync(company, true);

            return(CreatedAtRoute("Getcompany", new { id = company.Id }, company));
        }
        public async Task <IActionResult> CreateAsync([FromBody] CompanyCreateModel company)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            int createdCompanyId =
                await companyService.AddAsync(company.Name, company.CreationDate);

            return(CreatedAtAction(nameof(GetByIdAsync), new { id = createdCompanyId }));
        }
        public async Task <IActionResult> Create([Bind("IdentityDocumentNumber,BusinessName,Address")] CompanyEntity companyEntity)
        {
            companyEntity.UserId      = HttpContext.Session.GetInt32("userId").Value;
            companyEntity.CreatorUser = "";
            companyEntity.UpdaterUser = "";
            companyEntity.CreateDate  = DateTime.Now;
            companyEntity.UpdateDate  = DateTime.Now;
            companyEntity.Status      = true;
            companyEntity.Removed     = false;
            await _companyService.AddAsync(companyEntity);

            return(RedirectToAction("Index", "Company"));
        }
        public async Task <IActionResult> Create([FromBody] CompanyBindingModel company)
        {
            await companyService.AddAsync(new Core.Models.Company
            {
                Name     = company.Name,
                Exchange = company.Exchange,
                Ticker   = company.Ticker,
                ISIN     = company.ISIN,
                Website  = company?.Website
            });

            // TODO: Return id ??
            return(Ok());
        }
        public async Task <IActionResult> Save([FromBody] CompanyDto companyDto)
        {
            try
            {
                var newCompany = await _companyService.AddAsync(_mapper.Map <Company>(companyDto));

                await _distributedCache.RemoveAsync("companies");

                return(Created(string.Empty, _mapper.Map <CompanyDto>(newCompany)));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
                return(StatusCode(500, ex.Message));
            }
        }
Beispiel #10
0
        public async Task <IActionResult> PostAsync([FromBody] CompanyModel model)
        {
            try
            {
                await _companyService.AddAsync(model);

                return(Ok());
            }
            catch (CustomExceptions ex)
            {
                return(BadRequest(ex.Message));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
Beispiel #11
0
            public async Task <CompanyDto> Handle(Query request, CancellationToken cancellationToken)
            {
                var currentUser = await userManager.FindByIdAsync(userAccessor.GetCurrentUserId());

                if (await userManager.IsInRoleAsync(currentUser, RoleNames.Inspector))
                {
                    throw new RestException(HttpStatusCode.Forbidden, new { Forbidden = "Permission Denied." });
                }
                var doesExist = companyService.CheckExistsByName(request.Name);

                if (doesExist)
                {
                    throw new RestException(HttpStatusCode.BadRequest, new { Name = "Company name already exists." });
                }

                var newCompany = new Company
                {
                    Name      = request.Name,
                    CreatedOn = DateTime.UtcNow,
                    CreatedBy = currentUser.FullName,
                    UpdatedOn = null,
                    UpdatedBy = null,
                    IsActive  = true
                };

                var succeeded = await companyService.AddAsync(newCompany);

                if (!succeeded)
                {
                    throw new Exception("Error Saving New Company.");
                }

                var company = await companyService.FindByNameAsync(newCompany.Name);

                return(new CompanyDto(company));
            }
Beispiel #12
0
        public async Task <IActionResult> Add(CompanyViewModel vm)
        {
            if (ModelState.IsValid)
            {
                var businessEntities = await _businessEntityService.GetAllAsync();

                var businessEntity = businessEntities.FindBusinessEntity(vm.BusinessEntityName);

                if (businessEntity == null)
                {
                    return(View("Company", vm));
                }

                var dto    = CompanyViewModel.ToDto(vm, businessEntity);
                var result = await _companyService.AddAsync(dto);

                if (result)
                {
                    return(RedirectToAction("Index"));
                }
            }

            return(View("Company", vm));
        }
Beispiel #13
0
        public async Task <ActionResult <Company> > CreateAsync(Company company)
        {
            await _companyService.AddAsync(company);

            return(Ok(company));
        }
        public async Task <IActionResult> Register([FromBody] AccountViewModel model)
        {
            if (model != null)
            {
                try
                {
                    var user = new User()
                    {
                        CompanyId             = model.CompanyId,
                        TenantId              = tenant.Id,
                        Active                = model.Active,
                        Email                 = model.Email,
                        Password              = model.Password,
                        ConfirmPassword       = model.ConfirmPassword,
                        RecoveryEmail         = model.RecoveryEmail,
                        MobileNo              = model.MobileNo,
                        IsSystemAdministrator = model.IsSystemAdministrator,
                        IsConfirmed           = false,
                        UserName              = model.UserName,
                        LockoutEnabled        = model.LockoutEnabled,
                        TwoFactorEnabled      = model.TwoFactorEnabled
                    };

                    var companies = await companyService.ListAsync();

                    if (companies.Count == 0)
                    {
                        var company = new Company
                        {
                            Code     = tenant.Name,
                            Name     = tenant.Name,
                            TenantId = tenant.Id
                        };
                        await companyService.AddAsync(company);

                        await companyService.SaveAsync();

                        user.CompanyId = company.Id;
                    }

                    var result = await userManager.CreateAsync(user, model.Password);

                    if (result.Succeeded)
                    {
                        var confirmationCode = await userManager.GenerateEmailConfirmationTokenAsync(user);

                        var callbackUrl = Url.Action(
                            controller: "Account",
                            action: "ConfirmEmail",
                            values: new { userId = user.Id, code = confirmationCode },
                            protocol: Request.Scheme);
                        await emailSender.SendEmailAsync(
                            email : user.Email,
                            subject : "Confirm Email",
                            htmlMessage : callbackUrl
                            );

                        return(Ok(new { message = "User account registered successfully.", success = true }));
                    }
                    // await context.Users.AddAsync(user);
                    // await context.SaveChangesAsync();
                    return(BadRequest(new
                    {
                        message = "Failed to register user account.",
                        errors = result.Errors,
                        success = false
                    }));
                }
                catch (Exception ex)
                {
                    return(StatusCode(StatusCodes.Status500InternalServerError,
                                      new
                    {
                        message = "An error has occurred while registering a new user.",
                        success = false,
                        details = ex.Message
                    }));
                }
            }

            return(BadRequest());
        }
Beispiel #15
0
 public async Task Post([FromBody] CreateCompany company)
 {
     await _companyService.AddAsync(_mapper.Map <CreateCompany, CompanyDTO>(company));
 }
 public async Task <IActionResult> PostCompany([FromBody] Company company)
 {
     return(ApiOk(await CompanyService.AddAsync(company)));
 }
Beispiel #17
0
        public async Task <ActionResult> Save(CompanyViewModel companyViewModel)
        {
            var companyDto = Mapper.Map <CompanyDto>(companyViewModel);

            companyDto.AspNetUserId = User.Identity.Name;

            if (!ModelState.IsValid)
            {
                companyViewModel = new CompanyViewModel();
                return(View("CompanyForm", companyViewModel));
            }
            if (companyDto.Id == 0)
            {
                var path = fileManager.GeneratePictureName("/Files/Companies/");
                companyDto.PictureId = path;

                OperationDetails operationDetails = await companyService.AddAsync(companyDto);

                if (operationDetails.Succedeed)
                {
                    if (companyViewModel.Picture.Upload != null)
                    {
                        companyViewModel.Picture.Upload
                        .SaveAs(Server.MapPath(path));
                    }
                }
                else
                {
                    ModelState.AddModelError(operationDetails.Property, operationDetails.Message);
                    return(View("CompanyForm", companyViewModel));
                }
            }
            else
            {
                var  pictureLink = companyDto.PictureId;
                bool delete      = true;
                if (pictureLink == null)
                {
                    companyDto.PictureId = fileManager.GeneratePictureName("/Files/Companies/");
                    delete = false;
                }

                OperationDetails operationDetails = await companyService.EditAsync(companyDto);

                if (operationDetails.Succedeed)
                {
                    if (companyViewModel.Picture.Upload != null)
                    {
                        if (delete)
                        {
                            var pathToPicture = Server.MapPath(pictureLink);
                            if (fileManager.FileExists(pathToPicture))
                            {
                                fileManager.Delete(pathToPicture);
                            }
                        }
                        companyViewModel.Picture.Upload
                        .SaveAs(Server.MapPath(pictureLink));
                    }
                }
                else
                {
                    ModelState.AddModelError(operationDetails.Property, operationDetails.Message);
                    return(View("CompanyForm", companyViewModel));
                }
            }
            return(RedirectToAction("Index", "Companies"));
        }
        public async Task <ActionResult> ActivateClient(string code)
        {
            DomainPendingClient model;

            try
            {
                model = await _pendingClientService.GetAndDeleteAsync(code);
            }
            catch (NotFoundException)
            {
                return((ActionResult)RedirectToAction("Index", "Home"));
            }
            catch (Exception e)
            {
                Trace.TraceError("Failed to find client: {0}", e);
                return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError));
            }

            // Add profile
            var user = new DomainUser
            {
                ApplicationName = AppName,
                Name            = model.ContactPerson,
                Country         = model.Country,
                UserAgent       = _productIdExtractor.Get(Request.UserAgent),
                Email           = model.Email,
                Roles           = new List <string> {
                    DomainRoles.Client
                }
            };

            try
            {
                user = await _userService.AddAsync(user);
            }
            catch (ConflictException)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.Conflict));
            }
            catch (Exception e)
            {
                Trace.TraceError("Failed to create user profile for {0}: {1}", model.Email, e);
                return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError));
            }

            // Set user password
            try
            {
                await _passwordService.SetPasswordAsync(user.Id, model.Password, model.PasswordSalt);
            }
            catch (Exception e)
            {
                Trace.TraceError("Failed to set user {0} password: {1}", user.Id, e);
                return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError));
            }

            // Add company
            var company = new DomainCompany
            {
                Email   = model.Email,
                Name    = model.CompanyName,
                Address = model.Address,
                ZipCode = model.ZipCode,
                Phone   = model.PhoneNumber,
                Country = model.Country,
                Ein     = model.Ein,
                Users   = new List <string> {
                    user.Id
                }
            };

            try
            {
                await _companyService.AddAsync(company);
            }
            catch (Exception e)
            {
                Trace.TraceError("Failed to create company for user {0}: {1}", user.Id, e);
                return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError));
            }

            // Authenticate
            await _authenticationService.SetUserAsync(user, null, true);

            return(RedirectToRoute(RouteNames.ClientSubscriptions));
        }
Beispiel #19
0
        public async Task <ActionResult <CompanyDTO> > Add(CompanyDTO companyDTO)
        {
            var company = await _companyService.AddAsync(companyDTO);

            return(company);
        }