public ActionResult <IEnumerable <string> > PostCreateCompany([FromBody] CompanyDataDTO companyDataDTO) { try { var company = CompanyDAO.CreateCompany(companyDataDTO); var account = companyDataDTO.AccountDTO; var messageAccount = new MessageAccount(company.CompanyId, account.Fullname, account.Email, 2); Producer producer = new Producer(); producer.PublishMessage(message: JsonConvert.SerializeObject(messageAccount), "AccountGenerate"); return(new JsonResult(rm.Success("Save success"))); } catch { return(new JsonResult(rm.Error("Save fail"))); } }
public static Company CreateCompany(CompanyDataDTO companyData) { using (DeverateContext db = new DeverateContext()) { Company com = new Company(); com.Address = companyData.CompanyDTO.Address; com.Name = companyData.CompanyDTO.Name; com.CreateAt = DateTime.Now; com.Fax = companyData.CompanyDTO.Fax; com.Phone = companyData.CompanyDTO.Phone; com.IsActive = companyData.CompanyDTO.IsActive; var result = db.Company.Add(com); db.SaveChanges(); return(result.Entity); } }