/// <summary> /// 创建一个企业 /// </summary> /// <param name="validationErrors">返回的错误信息</param> /// <param name="db">数据库上下文</param> /// <param name="entity">一个企业</param> /// <returns></returns> public bool Create(ref ValidationErrors validationErrors, Company entity) { try { repository.Create(entity); return(true); } catch (Exception ex) { validationErrors.Add(ex.Message); ExceptionsHander.WriteExceptions(ex); } return(false); }
public static async Task SeedCompanies(ApplicationDbContext context) { var companyRepo = new CompanyRepository(context); var allCompanies = await companyRepo.GetAll(); if (allCompanies.Count == 0) { Company company = new Company() { Id = new Guid("476c2a3c-df4d-49cd-9395-33461aa19d8c"), Name = "Stantec", Address = "311 22ave SE", OfficePhone = "403-400-2123", OfficeEmail = "*****@*****.**", PostalCode = "T2C Z8L", City = "Calgary", Province = "Alberta", Country = "Canada", Contact = "George Orwell", ContactPhone = "587-222-3333", ContactEmail = "*****@*****.**" }; await companyRepo.Create(company); } }
private async void SaveCompany(object sender, EventArgs e) { var company = (Company)BindingContext; _company.Create(company); await Navigation.PopAsync(); }
public async Task <IActionResult> Create([FromBody] CreateCompanyReq req) { var cmd = new CreateCompanyCmd(req, HttpContext.UserId().Value); var company = await companyRepo.Create(cmd); return(Created($"/api/companies/${company.Id}", new CompanyResult(company))); }
public string Create(Company company, string userId) { var companyIdentity = Identity.Next(); var companyKey = PartionKeyRowKeyPair.CreateFromIdentity(companyIdentity); var userKey = PartionKeyRowKeyPair.CreateFromIdentity(userId); var userRepository = new UserRepository(_tableEntityOperation); var userTableEntity = userRepository.Get(userKey); var companyRepository = new CompanyRepository(_tableEntityOperation); var companyTableEntity = new CompanyTableEntity(companyKey, company.Name, new List <SmallUser> { new SmallUser { Id = userId, Name = userTableEntity.Name, Email = userTableEntity.Email } }); companyRepository.Create(companyTableEntity); TransientErrorHandling.Run(() => { userTableEntity = userRepository.Get(userKey); userTableEntity.Companies.Add(new Small { Id = companyIdentity, Name = company.Name }); userRepository.Update(userTableEntity); }); return(companyIdentity); }
public void Create(string[] args) { if (string.IsNullOrEmpty(currentTable)) { Console.WriteLine("Please select a Table first"); return; } switch (currentTable) { case "Address": addressRepository.Create(args); break; case "Company": companyRepository.Create(args); break; case "Department": departmentRepository.Create(args); break; case "Employee": employeeRepository.Create(args); break; } }
public Company InsertNew(CompanyRegister company) { CompanyUtil util = new CompanyService(); if (util.ObjectIsNull(company)) { throw new BadRequestException("Empresa não pode estar vazia"); } if (util.CNPJIsEmpty(company)) { throw new BadRequestException("CNPJ não pode estar em branco"); } if (!_cnpjValidate.ValidaCNPJ(company.CNPJ)) { throw new BadRequestException($"CNPJ inválido: {company.CNPJ}"); } if (util.CorporateSocialNameIsEmpty(company)) { throw new BadRequestException("RAZÃO SOCIAL deve ser preenchida"); } if (util.FantasyNameIsEmty(company)) { throw new BadRequestException("Preencha NOME FANTASIA por favor!"); } User user = _userRepository.GetUserManagerByCPF(company.CPF); if (user == null) { throw new BadRequestException("Não existe um administrador cadastrado com esse CPF"); } UserCompany userCompany = new UserCompany(); userCompany.UserId = user.Id; Company company1 = new Company(); company1.CNPJ = company.CNPJ; company1.CorporateSocialName = company.CorporateSocialName; company1.FantasyName = company.FantasyName; userCompany.CompanyId = company1.Id; company1.UserCompanies.Add(userCompany); try { _repository.Create(company1); return(company1); } catch (Exception e) { throw new Exception($"Tipo da excessão: {e.GetType()}"); } }
public void Register(RegisterModel model) { CompanyRepository <Employee> companyRepository = new CompanyRepository <Employee>(); companyRepository.Create(new Employee() { Login = model.Login, Name = model.Name, Password = model.Password }); }
private Company CreateMockCompany() { var entity = new Company { Id = 1, Name = "Test" }; var createdEntity = _repository.Create(entity); _context.SaveChanges(); return(createdEntity); }
public static void Main(string[] args) { CompanyRepository cr = new CompanyRepository(); cr.Create(new Company(10, "My Company", 20)); var parent = cr.Get(1); cr.AddChild(parent, new Company(10, "My Company2", 20)); Console.Read(); }
public Company Create(long userId, Company toAdd) { using (var tran = new TransactionScope()) { var toRet = _repository.Create(toAdd); BlLog.Log(userId, Module, "Delete company", "CompanyCreated", new object[] { toAdd.Id }); tran.Complete(); return(toRet); } }
public void Update() { var companyRepository = new CompanyRepository(); var company = companyRepository.Create("TestCompany1", null); var company1 = companyRepository.ReadAll().First(); company1.CompanyName.Is("TestCompany1"); company1.CompanyName = "HogeCompany"; companyRepository.Update(company1); var company2 = companyRepository.ReadAll().First(); company2.CompanyName.Is("HogeCompany"); }
public HttpResponseMessage CreateOrUpdate(CompanyRequest companyRequest) { string apiName = "CreateOrUpdate(CompanyRequest companyRequest=\n{" + companyRequest + "})"; var guid = Guid.NewGuid(); logger.Info("Guid: \"{0}\" api/{1}/{2} was invoked", guid, controllerName, apiName); ICompanyRepository companyRepository = new CompanyRepository(); try { if (!ModelState.IsValidField("companyRequest.Email")) { return(CreateGeneralResultMessage("Invalid Email Address", false, ApiStatusCodes.InvalidEmail)); } var companyToUpdate = companyRepository.GetByEmail(companyRequest.Email); if (companyToUpdate == null) {//Create logger.Info("Guid: \"{0}\" Start Creating new Company", guid); var newCompany = new Companies { Name = companyRequest.Name, Email = companyRequest.Email }; companyRepository.Create(newCompany); logger.Info("Guid: \"{0}\" Completed Creating new Company", guid); return(CreateResponseMessage(newCompany)); } else {//Update logger.Info("Guid: \"{0}\" Start Updating Company", guid); // companyToUpdate.Email = companyRequest.Email; companyToUpdate.Name = companyRequest.Name; companyRepository.SaveChanges(); logger.Info("Guid: \"{0}\" Completed Updating Company", guid); return(CreateResponseMessage(companyToUpdate)); } } catch (Exception ex) { logger.Error("Guid: \"{0}\" General Error: {1}", guid, ex); return(CreateGeneralResultMessage(ex.ToString(), false, ApiStatusCodes.InternalServerError)); } }
public ActionResult Create(Company company) { if (Session["admin"] != null) { if (ModelState.IsValid) { if (company != null) { var ad = Session["admin"] as Account; _companyRepository = new CompanyRepository(); var re = _companyRepository.Create(company, ad.UserId); return(Redirect(Url.Action("Details", new { id = int.Parse(re.ToString()) }))); } } } return(View()); }
// [RequiresAbsoluteRole(Role.Super, Role.Admin)] public async Task <IActionResult> CreateChildren(long companyId, [FromBody] CreateCompanyReq req) { req.ParentId = companyId; var userId = HttpContext.UserId().Value; var cmd = new CreateCompanyCmd(req, userId); var company = await companyRepo.Create(cmd); var cmd2 = new GivePermissionCmd( company.Id, userId, new CreatePermissionReq { RoleId = 601 }, userId ); var permission = await permissionRepo.Create(cmd2); return(Created($"/api/companies/${company.Id}", new CompanyResult(company))); }
public void GetIndexViewModel() { var parentCompany = _companyRepository.Create("ParentCompany", null); var childCompany = _companyRepository.Create("ChildCompany", parentCompany); _stockRepository.Create(parentCompany, _testBussinessCategory, "1234"); _stockRepository.Create(childCompany, _testBussinessCategory, "1235"); var resultViewModel = _workerService.GetIndexViewModel(); var resultCompany = resultViewModel.Companies.ElementAt(1); resultCompany.CompanyName.Is("ChildCompany"); resultCompany.ParentCompanyId.Is(parentCompany.CompanyId); }
public void Create() { var companyRepository = new CompanyRepository(); var company = companyRepository.Create("test", null); company = new CompanyRepository().Read(company.CompanyId); var bussinessRepository = new BussinessCategoryRepository(); var category = bussinessRepository.Create("aaa", "bbb"); var stockRepository = new StockRepository(); var stock = stockRepository.Create(company, category, "123"); var stock2 = new StockRepository(); var result = stock2.Read(stock.StockId); result.Company.CompanyId.Is(company.CompanyId); result.BussinessCategory.BussinessCategoryId.Is(category.BussinessCategoryId); result.StockCode.Is("123"); company = new CompanyRepository().Read(company.CompanyId); company.Stock.IsNotNull(); }
public void Create() { var companyRepository = new CompanyRepository(); var company = companyRepository.Create("name", null); var productRepository = new ProductRepository(); var product = productRepository.Create("test", DateTime.Now); var repository = new CompanyProductRelationRepository(); repository.Create(company, product); companyRepository = new CompanyRepository(); var result = companyRepository.Read(company.CompanyId); result.Products.First().ProductId.Is(product.ProductId); repository = new CompanyProductRelationRepository(); var relation = repository.Read(company.CompanyId, product.ProductId); relation.IsNotNull(); }
public void AddJob(Job job) { _companyRepositoryJob.Create(job); }
/// <summary> /// Create Company /// </summary> /// <param name="record"></param> /// <returns></returns> public async Task CreateCompany(CompanyViewModel record) { record.Password = Encryptor.Encrypt(record.Password); await companyRepository.Create(Mapper.Map <Company>(record)); }
public bool Create(CompanyRequest entity, HttpContext current = null) => _companyRepository.Create(CompanyRequest.ToEntity(entity));