public virtual async Task <int> CreateCompany(CreateCompanyOrContact input) { var id = 0; var discount = _DiscountRepository.GetAll().FirstOrDefault(); var data = _NewCompanyRepository.GetAll().Where(p => p.Name == input.Name && p.NewCustomerTypeId == input.NewCustomerTypeId).ToList(); if (data.Count == 0) { CreateCompany company = new CreateCompany() { Name = input.Name, NewCustomerTypeId = input.NewCustomerTypeId ?? null, AccountManagerId = input.AccountManagerId ?? null, CustomerId = input.CustomerId, ApprovedById = AbpSession.UserId, IsApproved = true, TradeLicense = input.TradeLicense, TRNnumber = input.TRNnumber, IndustryId = input.IndustryId ?? null, Discountable = discount != null ? (int)discount.Discountable : 0, UnDiscountable = discount != null ? (int)discount.UnDiscountable : 0, }; var companys = company.MapTo <NewCompany>(); id = _NewCompanyRepository.InsertAndGetId(companys); var comp = _NewCompanyRepository.GetAll().Where(p => p.Id == id).FirstOrDefault(); comp.CustomerId = "FN-" + input.Name.Substring(0, 3).ToUpper() + id; await _NewCompanyRepository.UpdateAsync(comp); } else { id = data[0].Id; } return(id); }
public virtual async Task <int> CreateCompany(CreateCompanyOrContact input) { int TenantId = (int)(AbpSession.TenantId); var id = 0; var data = _NewCompanyRepository.GetAll().Where(p => p.Name == input.Name && p.CustomerTypeId == input.CustomerTypeId && p.TenantId == TenantId).ToList(); if (data.Count == 0) { CreateCompany company = new CreateCompany(); company.Name = input.Name; company.CustomerTypeId = input.CustomerTypeId; company.AccountManagerId = input.AccountManagerId; company.CountryId = input.CountryId; company.CurrencyId = input.CurrencyId; company.TenantId = TenantId; var companys = company.MapTo <Company>(); id = _NewCompanyRepository.InsertAndGetId(companys); } else { id = data[0].Id; } return(id); }