public CompanyVo update(CompanyVo input, int?companyId = null) { using (var db = new MainDb()) { if (companyId == null) { companyId = input.companyId; } var res = db.companies.Include(i => i.contactInfo).FirstOrDefault(e => e.companyId == companyId); if (res == null) { return(null); } input.created = res.created; // input.createdBy = res.createdBy; db.Entry(res).CurrentValues.SetValues(input); db.SaveChanges(); return(res); } }
public CompanyVo insert(CompanyVo input) { using (var db = new MainDb()) { db.companies.Add(input); db.SaveChanges(); return(input); } }
private void CompanySetting_Load(object sender, EventArgs e) { int companyId = SystemConst.companyId; CompanyVo vo = SelectDao.SelectDataByID <CompanyVo>(companyId).FirstOrDefault(); if (vo != null) { this.textEdit1.Text = vo.Name; this.textEdit2.Text = vo.Address; this.textEdit3.Text = vo.Manager; this.memoRemark.Text = vo.Remark; } }
public ActionResult Edit(int id, CompanyVo input) { bool foundTheMatch = false; CompanyVo item = companyManager.get(id); if (this.ModelState.IsValid) { if (item.companyCategories != null) { foreach (CompanyCategoryLookupVo categoryLookupVo in item.companyCategoryLookupses) { foundTheMatch = false; foreach (int categoryTypeId in input.companyCategories) { if (categoryLookupVo.companyCategoryTypeId == categoryTypeId) { input.companyCategories.Remove(categoryTypeId); foundTheMatch = true; break; } } if (!foundTheMatch) { companyCategoryLookupManager.delete(categoryLookupVo.companyCategoryId); } } } if (input.companyCategories != null) { foreach (int categoryId in input.companyCategories) { var companyCategoryLookupVo = new CompanyCategoryLookupVo(); companyCategoryLookupVo.companyId = input.companyId; companyCategoryLookupVo.companyCategoryTypeId = categoryId; companyCategoryLookupVo.isActive = true; companyCategoryLookupManager.insert(companyCategoryLookupVo); } } contactInfoManager.update(input.contactInfo, input.contactInfo.contactInfoId); var res = companyManager.update(input, id); return(RedirectToAction("Index")); } return(View(input)); }
public IActionResult Put([FromBody] CompanyVo companyVo) { try { var companyEntity = _companyConverter.Parse(companyVo); _companyService.Update(companyEntity); return(Ok(companyVo)); } catch (ArgumentNullException e) { return(NotFound(e.Message)); } catch (Exception e) { return(BadRequest(e.Message + " | " + e.InnerException.Message)); } }
private void BtnQuery_Click(object sender, EventArgs e) { if (string.IsNullOrWhiteSpace(this.textEdit1.Text)) { XtraMessageBox.Show("公司名称不能为空!"); return; } CompanyVo vo = new CompanyVo() { Name = this.textEdit1.Text, Address = this.textEdit2.Text, Manager = this.textEdit3.Text }; object id; if ((id = InsertDao.InsertDataRetrunID(vo)) != null) { config.AppSettings.Settings["CompanyId"].Value = id.ToString(); XtraMessageBox.Show("操作成功!"); } }
public ActionResult Create(CompanyVo input) { if (this.ModelState.IsValid) { var item = companyManager.insert(input); if (input.companyCategories != null) { foreach (int categoryId in input.companyCategories) { var companyCategoryType = new CompanyCategoryLookupVo(); companyCategoryType.companyId = input.companyId; companyCategoryType.companyCategoryTypeId = categoryId; companyCategoryType.isActive = true; companyCategoryLookupManager.insert(companyCategoryType); } } return(RedirectToAction("Index")); } return(View(input)); }
// public List <CompanyVo> getAllOfGivenCategory(int companyCategoryTypeId, bool?isActive = true) { using (var db = new MainDb()) { List <CompanyVo> companyList = new List <CompanyVo>(); var query = ( from _company in db.companies join _contactInfo in db.contactInfos on _company.contactInfoId equals _contactInfo.contactInfoId from _companyCategoryLookup in db.companyCategoryLookups.Where(cct => _company.companyId == cct.companyId).DefaultIfEmpty() from _Referral in db.referrals.Where(_Referral => _company.companyId == _Referral.companyId).DefaultIfEmpty() from _surveyAnswers in db.surveyAnswers.Where(_surveyAnswers => _surveyAnswers.referralId == _Referral.referralId).DefaultIfEmpty() where _companyCategoryLookup.companyCategoryTypeId == companyCategoryTypeId group new { _company.companyId, _company.companyName, _contactInfo.firstName, _contactInfo.lastName, _contactInfo.workPhone, _company.license, _company.bonded, _company.agreementSigned, _surveyAnswers } by new { _company.companyId, _company.companyName, _contactInfo.firstName, _contactInfo.lastName, _contactInfo.workPhone, _company.license, _company.bonded, _company.agreementSigned } into g select new { companyId = g.Key.companyId, companyName = g.Key.companyName, firstName = g.Key.firstName, lastName = g.Key.lastName, workPhone = g.Key.workPhone, license = g.Key.license, bonded = g.Key.bonded, agreementSigned = g.Key.agreementSigned, a_score = ((decimal?)g.Sum(t => t._surveyAnswers.answer) / g.Count(u => u._surveyAnswers.answer != null)) * 20, score = ((decimal?)g.Select(u => u._surveyAnswers.answer).Sum() / g.Count(u => u._surveyAnswers.answer != null)) * 20, scoreCount = g.Select(u => u._surveyAnswers.referralId).Distinct().Count(z => z != null) } ); var items = query.ToList(); foreach (var obj in items) { CompanyVo c = new CompanyVo(); c.contactInfo = new ContactInfoVo(); c.companyId = obj.companyId; c.companyName = obj.companyName; c.contactInfo.firstName = obj.firstName; c.contactInfo.lastName = obj.lastName; c.contactInfo.workPhone = obj.workPhone; c.score = (obj.score != null) ? (decimal?)Math.Round(obj.score.GetValueOrDefault(), 2) : null; c.scoreCount = obj.scoreCount; companyList.Add(c); } return(companyList); } }
public ActionResult Create() { var vo = new CompanyVo(); return(View(vo)); }