public ActionResult Company() { try { int id = UserBL.ReadAll().First(u => u.Name == User.Identity.GetUserName()).Id; var company = (CompanyViewModel)CompanyBL.Read(Convert.ToInt32(id)); //ERROR Couldn't convert //company.Employees = (EmployeeViewModel)EmployeeBL.ReadByCompany(company.Id); if (company.Employees == null) { company.Employees = new List <EmployeeViewModel>(); } if (company.Groups == null) { company.Groups = new List <GroupViewModel>(); } if (company.Positions == null) { company.Positions = new List <PositionViewModel>(); } return(View(company)); } catch (Exception) { return(View((CompanyViewModel)CompanyBL.Read(Convert.ToInt32(-1)))); throw; } }
// GET: Employee public ActionResult Create() { var id = UserBL.ReadAll().First(u => u.Name == User.Identity.GetUserName()).Id; ViewBag.Positions = PositionBL.ReadByCompany(CompanyBL.Read(id).Id); ViewBag.Groups = GroupBL.ReadByCompany(CompanyBL.Read(id).Id); return(View(new EmployeeViewModel())); }
public ActionResult Create(PositionViewModel viewModel) { try { if (ModelState.IsValid) { var id = UserBL.ReadAll().First(u => u.Name == User.Identity.GetUserName()).Id; viewModel.CompanyId = CompanyBL.Read(id).Id; PositionBL.Create(viewModel); return(RedirectToAction("../Company/Company")); } return(View(new PositionViewModel())); } catch { return(View(new PositionViewModel())); } }
//[ValidateAntiForgeryToken] public bool Edit(CompanyViewModel viewModel) { try { if (ModelState.IsValid) { int id = UserBL.ReadAll().First(u => u.Name == User.Identity.GetUserName()).Id; var oldModel = (CompanyViewModel)CompanyBL.Read(Convert.ToInt32(id)); oldModel.Name = viewModel.Name; oldModel.Address = viewModel.Address; oldModel.Mail = viewModel.Mail; CompanyBL.Update(oldModel); return(true); } throw new Exception(); } catch (Exception) { ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator."); throw; } }