예제 #1
0
        public async Task <IActionResult> CreateAsync([FromBody] Company model)
        {
            try
            {
                if (model.ValidationErrors().Any())
                {
                    return(StatusCode((int)HttpStatusCode.PreconditionFailed, string.Join(" | ", model.ValidationErrors())));
                }

                var newCompany = new Company
                {
                    Id          = model.Id,
                    Name        = model.Name,
                    About       = model.About,
                    LogoUrl     = model.LogoUrl,
                    CreatedOn   = DateTime.Now,
                    UpdatedOn   = DateTime.Now,
                    IsDisplayed = true,
                    IsDeleted   = false
                };

                var result = await _service.AddCompanyAsync(newCompany);

                if (result)
                {
                    return(StatusCode((int)HttpStatusCode.OK, "Company created successfully !!!"));
                }
                return(StatusCode((int)HttpStatusCode.OK, "Company not created !!!"));
            }
            catch (Exception ex) { return(StatusCode((int)HttpStatusCode.InternalServerError, ex.Message)); }
        }
예제 #2
0
        public async Task <IActionResult> AddCompany(CompanyViewModel vm)
        {
            await cService.AddCompanyAsync(vm.Name, vm.CreationDate);

            var vm1 = new CompanySearchViewModel();

            return(View("Index", vm1));
        }
예제 #3
0
        public async Task <IActionResult> AddCompany(AddCompanyViewModel model)
        {
            if (ModelState.IsValid)
            {
                await _companyService.AddCompanyAsync(model);
            }

            return(View());
        }
예제 #4
0
        public async Task <IActionResult> Create(CompanyFormModel model)
        {
            if (this.ModelState.IsValid)
            {
                try
                {
                    if (string.IsNullOrWhiteSpace(model.ManagerName) || string.IsNullOrWhiteSpace(model.ManagerEmail))
                    {
                        model.IsSuccess   = false;
                        model.FormMessage = "Firma yetkilisi bilgileri girilmelidir.";
                        return(this.View((object)model));
                    }
                    IFormFile logoFile       = model.LogoFile;
                    string    uniqueFileName = null;
                    if (logoFile != null && logoFile.Length > 0)
                    {
                        uniqueFileName = FileHelper.GetUniqueFileName(logoFile.FileName);
                        if (string.IsNullOrWhiteSpace(_hostingEnvironment.WebRootPath))
                        {
                            _hostingEnvironment.WebRootPath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot");
                        }
                        string path  = Path.Combine(_hostingEnvironment.WebRootPath, "admin/uploads");
                        string path2 = Path.Combine(path, uniqueFileName);
                        using (FileStream stream = new FileStream(path2, FileMode.Create))
                        {
                            await logoFile.CopyToAsync((Stream)stream, default(CancellationToken));
                        }
                    }
                    CompanyDetailDTO companyDetailDTO = Mapper.Map <CompanyFormModel, CompanyDetailDTO>(model);
                    companyDetailDTO.Image = uniqueFileName;
                    PanelUserDTO manager = new PanelUserDTO
                    {
                        Email   = model.ManagerEmail,
                        Name    = model.ManagerName,
                        Surname = model.ManagerSurname
                    };
                    Result <CompanyDetailDTO> result = await _companyService.AddCompanyAsync(companyDetailDTO, manager);

                    model.FormMessage = result.FormMessage;
                    model.IsSuccess   = result.IsSuccess;
                    if (model.IsSuccess)
                    {
                        model.FormMessage = "İşleminiz başarılı bir şekilde gerçekleştirildi.";
                    }
                    return(this.View((object)model));
                }
                catch (Exception ex)
                {
                    LoggerExtensions.LogError(_logger, ex, "Create Error", Array.Empty <object>());
                    model.IsSuccess   = false;
                    model.FormMessage = "İşleminiz gerçekleştirilemedi.";
                    return(this.View((object)model));
                }
            }
            return(this.View((object)model));
        }
예제 #5
0
        public async Task <IActionResult> Post([FromBody] Company company)
        {
            try
            {
                await _CompanyService.AddCompanyAsync(company);

                return(Ok(Json(company)));
            }
            catch (Exception ex)
            {
                return(StatusCode(500, ex.Message));
            }
        }
        public async Task <IActionResult> Create([FromBody] CompanyDto companyDto)
        {
            await _companyService.AddCompanyAsync(companyDto);

            return(Ok());
        }