// GET: Companies/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } CompanyTO company = cmpRepo.getAllCompanybyId(id); List <UserAccess> userAccess = cmpRepo.getAllUserAccess().Where(x => x.CompanyId == id).ToList(); List <int> userRoleId = new List <int>(); foreach (var item in userAccess) { userRoleId.Add(item.UserRoleId); } var userRolesIsAdmin = cmpRepo.getAllUserrole().Where(c => userRoleId.Contains(c.UserRoleId)).Select(x => new { x.EmailId, x.IsAdmin }).ToList(); //string contactEmailId= company.Company_Admin = userRolesIsAdmin.Where(x => x.IsAdmin == true).Select(x => x.EmailId).FirstOrDefault(); company.Company_Contacts = userRolesIsAdmin.Where(x => x.IsAdmin == false).Select(x => x.EmailId).FirstOrDefault(); if (company == null) { return(HttpNotFound()); } return(View(company)); }
private static CompanyTO MapElement(DataRow row) { CompanyTO company = new CompanyTO(); company.ID = Convert.ToInt32(row["ID"]); company.Name = Convert.ToString(row["Name"]); company.Logo = Convert.ToString(row["LogoPath"]); company.ContactName = Convert.ToString(row["ContactName"]); company.ContactEmail = Convert.ToString(row["ContactEmail"]); return(company); }
// GET: Companies/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } CompanyTO company = cmpRepo.getAllCompanybyId(id); if (company == null) { return(HttpNotFound()); } return(View(company)); }
public void saveCompany(CompanyTO company) { Company dataTOsave = new Company() { Company_Name = company.Company_Name, CompanyColor = company.CompanyColor, Company_Admin = company.Company_Admin, Company_Contacts = company.Company_Contacts, IsActive = true }; db.Companies.Add(dataTOsave); db.SaveChanges(); int companyId = db.Companies.Where(x => x.Company_Name == company.Company_Name).Select(x => x.Company_Id).FirstOrDefault(); if (company.Company_Admin != "") { UserRole users = new UserRole(); users.EmailId = company.Company_Admin; users.IsAdmin = true; saveUserrole(users); UserAccess Role = new UserAccess() { CompanyId = companyId, UserRoleId = getAllUserrole().Where(x => x.EmailId == company.Company_Contacts).Select(x => x.UserRoleId).FirstOrDefault() }; saveUserAccess(Role); } if (company.Company_Contacts != "") { UserRole users = new UserRole(); users.EmailId = company.Company_Admin; users.IsAdmin = false; saveUserrole(users); UserAccess Role = new UserAccess() { CompanyId = companyId, UserRoleId = getAllUserrole().Where(x => x.EmailId == company.Company_Contacts).Select(x => x.UserRoleId).FirstOrDefault() }; saveUserAccess(Role); } db.SaveChanges(); }
public static CompanyTO GetById(int id) { CompanyTO company = null; string execCommand = String.Format( " SELECT ID, Name, LogoPath, ContactName, ContactEmail " + " FROM company " + " WHERE ID = {0}", id); DataTable table = ExecuteCommand(execCommand); if (table != null && table.Rows.Count > 0) { company = MapElement(table.Rows[0]); } return(company); }
public ActionResult Create([Bind(Include = "Company_Id,Company_Name,IsActive,Company_Contacts,Company_Admin,CompanyColor")] CompanyTO company) { if (company.Company_Name != "" && company.CompanyColor != "") { var Color_exist = cmpRepo.getAllCompanies().Where(x => x.CompanyColor == company.CompanyColor).FirstOrDefault(); if (Color_exist != null && Color_exist.Company_Id != company.Company_Id) { ModelState.AddModelError(string.Empty, "Please choose different color"); return(View(company)); } //logic to enter the users else { cmpRepo.saveCompany(company); } return(RedirectToAction("Index")); } return(View(company)); }
public void GetById_CompanyDoesNotExist_CompanyIsNull() { Company company = new Company(); CompanyTO info = company.Get(0); Assert.IsNull(info); }
public void GetById_DefaultCompanyHasID_IdSentEqualToReceived() { Company company = new Company(); CompanyTO info = company.Get(DEFAULT_ID); Assert.AreEqual(DEFAULT_ID, info.ID); }
public void GetById_DefaultCompanyHasEmail_EmailHasValue() { Company company = new Company(); CompanyTO info = company.Get(DEFAULT_ID); Assert.AreEqual(true, !String.IsNullOrEmpty(info.ContactEmail)); }
public void GetById_DefaultCompanyHasName_NameHasValue() { Company company = new Company(); CompanyTO info = company.Get(DEFAULT_ID); Assert.AreEqual(true, !String.IsNullOrEmpty(info.Name)); }
public void GetById_DefaultCompanyExists_CompanyIsNotNull() { Company company = new Company(); CompanyTO info = company.Get(DEFAULT_ID); Assert.IsNotNull(info); }
public CompanyTO Get(int id) { info = CompanyPersistence.GetById(id); return(info); }
public Company() { info = null; }