public async Task <ActionResult <CompanyDto> > CreateCompanyWithBankruptTime(CompanyAddWithBankruptTimeDto company) { //在3.0之前需要这样写 //现在不需要了,因为当Controller使用[ApiController]属性进行注解的时候,如果遇到验证错误 //那么就会自动返回400错误 //if (!ModelState.IsValid) //{ // return UnprocessableEntity(ModelState); //} var entity = _mapper.Map <Company>(company); _companyRepository.AddCompany(entity); await _companyRepository.SaveAsync(); var returnDto = _mapper.Map <CompanyDto>(entity); var links = CreateLinksForCompany(returnDto.Id, null); var linkedDict = returnDto.ShapeData(null) as IDictionary <string, object>; linkedDict.Add("links", links); return(CreatedAtRoute(nameof(GetCompany), new { companyId = linkedDict["Id"] }, linkedDict)); }
public async Task <string> AddGC(GroupCompanyModel gcmodel) { int insertedgroupid = 0; int insertedCompanyid = 0; Group group = GroupRepository.Groups.FirstOrDefault(g => g.GroupName == gcmodel.GroupName); if (group != default(Group)) { Company company = CompanyRepository.Companys.FirstOrDefault(c => c.CompanyName == gcmodel.CompanyName && c.GroupId == group.GroupId); if (company == default(Company)) { insertedCompanyid = await CompanyRepository.AddCompany(new Company { GroupId = group.GroupId, CompanyName = gcmodel.CompanyName, RegisteredAddress = gcmodel.RegisteredAddress, CreatedDate = gcmodel.CreatedDate, CreatedBy = gcmodel.CreatedBy }); } } else { insertedgroupid = await GroupRepository.AddGroup(new Group { GroupName = gcmodel.GroupName, CreatedDate = gcmodel.CreatedDate, CreatedBy = gcmodel.CreatedBy }); insertedCompanyid = await CompanyRepository.AddCompany(new Company { GroupId = insertedgroupid, CompanyName = gcmodel.CompanyName, RegisteredAddress = gcmodel.RegisteredAddress, CreatedDate = gcmodel.CreatedDate, CreatedBy = gcmodel.CreatedBy }); //insertedProjectid = await ProjectRepository.AddProject(new Project { GroupId = insertedgroupid, CompanyId = insertedCompanyid, ProjectName = gcpmodel.ProjectName, CreatedDate = gcpmodel.CreatedDate, CreatedBy = gcpmodel.CreatedBy }); //insertcostbreakup = await CostBreakupRepository.AddCostBreakup(new CostBreakup { ProjectID = insertedProjectid, CreatedDate = gcpmodel.CreatedDate, CreatedBy = gcpmodel.CreatedBy }); } return(insertedCompanyid > 0 ? "Successfully added Group and Company" : "Group and Company already exist"); }
public async Task <ActionResult <CompanyDto> > AddCompany(CompanyAddDto companyAddDto) { var company = _mapper.Map <Company>(companyAddDto); _companyRepository.AddCompany(company); bool result = await _companyRepository.SaveAsync(); var returnDto = _mapper.Map <CompanyDto>(company); return(CreatedAtRoute(nameof(GetCompany), new { companyId = returnDto.Id }, returnDto)); }
public async Task <ActionResult <CompanyDto> > CreateCompanyWithBankruptTime(CompanyAddWithBankruptTimeDto company) { var entity = _mapper.Map <Company>(company); _companyRepository.AddCompany(entity); await _companyRepository.SaveAsync(); var returnDto = _mapper.Map <CompanyDto>(entity); var links = CreateLinksForCompany(returnDto.Id, null); var linkedDict = returnDto.ShapeData(null) as IDictionary <string, object>; linkedDict.Add("links", links); return(CreatedAtRoute(nameof(GetCompany), new { companyId = linkedDict["Id"] }, linkedDict)); }
public async Task <ActionResult <CompanyDto> > AddCompany([FromBody] CompanyForCreationDto companyForCreation) { var validationResults = new CompanyForCreationDtoValidator().Validate(companyForCreation); validationResults.AddToModelState(ModelState, null); if (!ModelState.IsValid) { return(BadRequest(new ValidationProblemDetails(ModelState))); //return ValidationProblem(); } var company = _mapper.Map <Company>(companyForCreation); await _companyRepo.AddCompany(company); var saveSuccessful = await _companyRepo.SaveAsync(); if (saveSuccessful) { var companyFromRepo = await _companyRepo.GetCompanyAsync(company.Id); var companyDto = _mapper.Map <CompanyDto>(companyFromRepo); var response = new Response <CompanyDto>(companyDto); return(CreatedAtRoute("GetCompany", new { company.Id }, response)); } return(StatusCode(500)); }
public async Task <ActionResult <CompanyDto> > CreateCompany(CompanyAddDto companyAddDto) { //post 把是参数把是参数dto转为companydto转为company存入数据库 //Id 应该在api生成 //老版本的需要检查 新版本apicontroller会自动返回badrequest if (companyAddDto == null) { return(BadRequest()); } var entity = _mapper.Map <Company>(companyAddDto); _companyRepository.AddCompany(entity); try { var succss = await _companyRepository.SaveAsync(); } catch (Exception ex) { throw; } var dto = _mapper.Map <CompanyDto>(entity); var links = CreateLinksForCiampany(dto.Id, null); var linksDict = dto.ShapeData(null) as IDictionary <string, object>; linksDict.Add("links", links); return(CreatedAtRoute(nameof(GetCompany), new { companyid = dto.Id }, linksDict));//调用getcompany方达,填写路由 }
public IActionResult AddCompany(AddCompanyDTO addCompany) { if (addCompany == null || string.IsNullOrEmpty(addCompany.City) || string.IsNullOrEmpty(addCompany.Country) || string.IsNullOrEmpty(addCompany.Mail) || string.IsNullOrEmpty(addCompany.Name) || string.IsNullOrEmpty(addCompany.Phone) || string.IsNullOrEmpty(addCompany.Street)) { return(BadRequest()); } if (addCompany.PostalCode < 1000 || 9999 < addCompany.PostalCode) { return(BadRequest()); //Belgian postal codes } if (addCompany.HouseNumber < 1 || 999 < addCompany.HouseNumber) { return(BadRequest()); //House numbers } Company company = Company.MapAddCompanyDTOToCompany(addCompany); if (_companyRepo.CompanyExists(company)) { return(StatusCode(303)); } _companyRepo.AddCompany(company); try { _companyRepo.SaveChanges(); return(Ok()); } catch (Exception) { return(StatusCode(500)); } }
public async Task <IActionResult> CreateCompany([FromBody] CompanyAddDto companyAddDto) { //Task<IActionResult> = Task<ActionResult<CompanyDto> //使用 [ApiController] 属性后,会自动返回400错误,无需再使用以下代码: //if (!ModelState.IsValid) //{ // return UnprocessableEntity(ModelState); //} //Core 3.x 使用 [ApiController] 属性后,无需再使用以下代码: //if (company == null) //{ // return BadRequest(); //返回状态码400 //} var entity = _mapper.Map <Company>(companyAddDto); _companyRepository.AddCompany(entity); //controller不需要知道repository细节 await _companyRepository.SaveAsync(); var returnDto = _mapper.Map <CompanyDto>(entity); var links = CreateLinksForCompany(returnDto.Id, null); var linkedDict = returnDto.ShapeData(null) as IDictionary <string, object>; linkedDict.Add("links", links); //返回状态码201 //通过使用 CreatedAtRoute 返回时可以在 Header 中添加一个地址(Loaction)包含一个url找到新建资源 return(CreatedAtRoute(nameof(GetCompany), new { companyId = linkedDict["Id"] }, linkedDict)); }
public async Task <IActionResult> PostCompany([FromBody] AddCompanyModel company) { ClaimsIdentity identity = HttpContext.User.Identity as ClaimsIdentity; string role = identity.FindFirst("Role").Value; if (role == "Admin") { var result = await _repo.AddCompany(company); if (result) { return(Ok(new Response { Status = "Success", Message = "Company Posted successfully" })); } else { return(BadRequest(new Response { Status = "Failed", Message = "Company creation unsuccessfully" })); } } else { return(Unauthorized(new Response { Status = "Failed", Message = "Company creation unsuccessfully. Only Admins can create" })); } }
public async Task <IActionResult> CreateCompany([FromBody] CompanyAddDto company) //Task<IActionResult> = Task<ActionResult<CompanyDto> { //使用 [ApiController] 属性后,会自动返回400错误,无需再使用以下代码: //if (!ModelState.IsValid) //{ // return UnprocessableEntity(ModelState); //} //Core 3.x 使用 [ApiController] 属性后,无需再使用以下代码: //if (company == null) //{ // return BadRequest(); //返回状态码400 //} var entity = _mapper.Map <Company>(company); _companyRepository.AddCompany(entity); await _companyRepository.SaveAsync(); var returnDto = _mapper.Map <CompanyDto>(entity); //返回状态码201 //通过使用 CreatedAtRoute 返回时可以在 Header 中添加一个地址(Loaction) return(CreatedAtRoute(nameof(GetCompany), new { companyId = returnDto.Id }, returnDto)); }
public async Task <IActionResult> AddCompany([FromBody] Company model) { if (ModelState.IsValid) { try { var companyId = await companyRepository.AddCompany(model); if (companyId > 0) { return(Ok(companyId )); } else { return(NotFound()); } } catch (Exception) { return(BadRequest()); } } return(BadRequest()); }
private void AddCompany() { var company = new Company { CompanyName = CompanyNameInput.Text, CompanyId = Guid.NewGuid(), PostCode = PostCodeInput.Text, City = CityInput.Text, Address = AddressInput.Text, Email = EmailInput.Text, Phone = PhoneInput.Text, CompanyType = CompanyCustomer.IsChecked != null && (bool)CompanyCustomer.IsChecked ? CompanyType.Customer : CompanyType.Producer }; _db.AddCompany(company); try { _db.SaveChanges(); } catch (DbEntityValidationException e) { DbExceptionValidate("Bład dodania Firmy", e); } catch (Exception e) { MessageBox.Show("Błąd dodania Firmy : " + e.Message, "Uwaga", MessageBoxButton.OK, MessageBoxImage.Error); } SetEdited(false); this.Close(); }
public async Task <IActionResult> AddCompany([FromBody] AppCompany model) { if (ModelState.IsValid) { try { logger.LogInformation("Adding Company in Repository"); var addedCompany = await companyRepo.AddCompany(model); if (addedCompany != null) { return(Ok(addedCompany)); } else { return(NotFound()); } } catch (Exception excp) { logger.LogError("Error Adding Company in Repository " + excp.Message); return(BadRequest(excp)); } } return(BadRequest()); }
public async Task <bool> ExtractDataFromStream(Stream stream) { var columnsList = new List <int>(); Dictionary <string, int> headers = null; using (var reader = new StreamReader(stream)) { while (!reader.EndOfStream) { var line = reader.ReadLine(); var values = line?.Split(','); if (values?.Length > 1) { headers = headers ?? _fileColumnsFormatter.ReadColumnIndexes(values, columnsList); var company = _fileColumnsFormatter.FormCompany(values, columnsList); await _companyRepository.AddCompany(company); } } } return(true); }
public async Task <IActionResult> CreateCompany([FromBody] CompanyAddDto company, [FromHeader(Name = "Accept")] string acceptMediaType) { //使用 [ApiController] 属性后,会自动返回400错误,无需再使用以下代码: //if (!ModelState.IsValid) { return UnprocessableEntity(ModelState); } //Core 3.x 使用 [ApiController] 属性后,无需再使用以下代码: //if (company == null) { return BadRequest(); } //尝试解析 MediaTypeHeaderValue(视频P43) if (!MediaTypeHeaderValue.TryParse(acceptMediaType, out MediaTypeHeaderValue parsedAcceptMediaType)) { return(BadRequest()); } //是否需要 links(HATEOAS)(视频P41-43) bool includeLinks = parsedAcceptMediaType.SubTypeWithoutSuffix .EndsWith("hateoas", StringComparison.InvariantCultureIgnoreCase); //大小写不敏感 //是否需要 Full Dto bool isFull = parsedAcceptMediaType.SubTypeWithoutSuffix .ToString() .Contains("full", StringComparison.InvariantCultureIgnoreCase); var entity = _mapper.Map <Company>(company); _companyRepository.AddCompany(entity); await _companyRepository.SaveAsync(); var shapedData = isFull ? _mapper.Map <CompanyFullDto>(entity).ShapeData(null) : _mapper.Map <CompanyFriendlyDto>(entity).ShapeData(null); if (includeLinks) { var companyDict = shapedData as IDictionary <string, object>; var links = CreateLinksForCompany(entity.Id, null); companyDict.Add("links", links); //返回状态码201 //通过使用 CreatedAtRoute 返回时可以在 Header 中添加一个地址(Loaction) return(CreatedAtRoute(nameof(GetCompany), new { companyId = entity.Id }, companyDict)); } return(CreatedAtRoute(nameof(GetCompany), new { companyId = entity.Id }, shapedData)); }
private void SaveDataToDatabase() { companyRepository.AddCompany(dataExtraction.GetStockData()); scrapeInfoRepository.AddScrapeInfo(dataExtraction.GetStockData(), UserId); stockDataRepository.AddStockData(dataExtraction.GetStockData(), scrapeInfoRepository, companyRepository, UserId); }
public async Task <ActionResult <CompanyDto> > CreateCompany(CompanyAddDto company) { var entity = mapper.Map <CompanyAddDto, Company>(company); services.AddCompany(entity); await services.SaveAsync(); return(CreatedAtAction(nameof(GetCompanyById), new { companyid = entity.Id }, mapper.Map <Company, CompanyDto>(entity))); }
public Company AddCompany(CompanyModel companyСlient, string userId) { var company = companyСlient.GetCompany(); company.UserId = userId; _companyRepository.AddCompany(company); _context.SaveChanges(); return(company); }
public IActionResult AddCompany([FromBody] CompanyViewModel model) { var comp = new Company { Name = model.Name }; var newComp = _companyRepository.AddCompany(comp); var compVM = _mapper.Map <CompanyViewModel>(newComp); return(Ok(compVM)); }
public async Task <ActionResult <CompanyDto> > AddCompany(CompanyAddDto addDto) { var company = _mapper.Map <Company>(addDto); _repository.AddCompany(company); await _repository.SaveChangesAsync(); var dto = _mapper.Map <CompanyDto>(company); return(CreatedAtRoute(nameof(GetCompany), new { companyId = company.Id }, dto)); }
public async Task <ActionResult <CompanySearchResDto> > AddCompany(CompanyAddDto company) { var entity = mapper.Map <Company>(company); companyRepository.AddCompany(entity); await companyRepository.SaveAsync(); var companySearchDto = mapper.Map <CompanySearchResDto>(entity); return(CreatedAtRoute(nameof(GetCompany), new { companyId = entity.Id }, companySearchDto)); }
public async Task <ActionResult <CompanyDto> > CreateCompany([FromBody] CompanyAddDto companyAdd) { var company = _mapper.Map <Company>(companyAdd); _companyRepository.AddCompany(company); await _companyRepository.SaveAsync(); var returnDto = _mapper.Map <CompanyDto>(company); return(CreatedAtAction(nameof(GetCompany), new { companyId = company.Id }, returnDto)); }
public IActionResult Post([FromBody] CompanyEmployeeDTO value) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var companyid = _companyRepository.AddCompany(value); return(Ok(new { id = companyid })); }
public async Task <ActionResult <CompanyAddDto> > CreateCompany(CompanyAddDto company) { var entity = _mapper.Map <Company>(company); _companyRepository.AddCompany(entity); await _companyRepository.SaveAsync(); var ReturnDto = _mapper.Map <CompanyDto>(entity); return(CreatedAtRoute(nameof(GetCompany), new { companyId = ReturnDto.Id }, ReturnDto)); }
public ActionResult <CompanyDto> CreateCompany(CompanyForCreationDto company) { var companyEntity = _mapper.Map <Entities.Company>(company); _companyRepository.AddCompany(companyEntity); _companyRepository.Save(); var companyToReturn = _mapper.Map <CompanyDto>(companyEntity); var links = CreateLinksForCompany(companyToReturn.Id, null); var linkedResourceToReturn = companyToReturn.ShapeData(null) as IDictionary <string, object>; linkedResourceToReturn.Add("links", links); return(CreatedAtRoute("GetCompany", new { companyId = linkedResourceToReturn["Id"] }, linkedResourceToReturn)); }
public async Task <ActionResult <CompanyDto> > CreateCompany([FromBody] CompanyAddDto company) { //xml格式 Introduction null //把Introduction 放在Name字段前可识别 var entity = _mapper.Map <Company>(company); _companyRepository.AddCompany(entity); await _companyRepository.SaveAsync(); var retuenDto = _mapper.Map <CompanyDto>(entity); var links = CreateLinksForCompany(retuenDto.Id, null); var linkedDict = retuenDto.ShapeData(null) as IDictionary <string, object>; linkedDict.Add("links", links); //返回一个路径,获取当前添加的资源 return(CreatedAtRoute(nameof(GetCompany), new { companyId = linkedDict["Id"] }, retuenDto)); }
public async Task <IActionResult> AddNewCompany([FromBody] CompanyDetailViewModel company, string userid) { try { return(Ok(await _trasection.AddCompany(company, userid))); } catch (Exception) { return(StatusCode(StatusCodes.Status500InternalServerError, "Error occure during Registeration")); } }
public async Task <ActionResult <CompanyDto> > CreateCompanyAsync([FromBody] CompanyAddDto company) { // post 需要返回201状态码 var entity = _mapper.Map <Company>(company); _companyRepository.AddCompany(entity); await _companyRepository.SaveAsync(); var returnDto = _mapper.Map <CompanyDto>(entity); return(CreatedAtAction(nameof(GetCompany), new { companyId = returnDto.Id }, returnDto)); }
public Company OnRegistration(RegisterCompanyCommand command) { var company = Company.Create(command.Name, command.Services) .AddDetails(command.Url, command.NumberEmployees, command.DateEstablished) .AddLocation( Location.Create(command.AddressLine1, command.City, command.State, command.ZipCode) .SetCorporate(true) .SetAdditionalAddress(command.AddressLine2) ); _companyRepo.AddCompany(company); return(company); }
public ActionResult AddCompany(Companies m_Company) { if (ModelState.IsValid) { CompanyRepository.AddCompany(m_Company); return(RedirectToAction("Index")); } else { ViewBag.CompanyTypes = CompanyRepository.GetCompanyTypes(); return(View("AddCompany", m_Company)); } }