public ActionResult DefineStructure(StructureDetails viewModel) { IStructuredetailRepository objstruct = new StructuredetailRepository(); var validate = objstruct.Getcondition(viewModel.CompanyCode, viewModel.CityCode, viewModel.CityName).FirstOrDefault(); var validate1 = objstruct.Getcondition1(viewModel.CompanyCode, viewModel.CityCode).FirstOrDefault(); var validate3 = objstruct.Getcondition2(viewModel.CityCode, viewModel.CityName).FirstOrDefault(); var check = objstruct.Getcondition3(viewModel.CityCode).FirstOrDefault(); var check1 = objstruct.Getcondition4(viewModel.CityName).FirstOrDefault(); var check2 = objstruct.Getcondition5(viewModel.CompanyCode).FirstOrDefault(); if (validate == null && validate3 != null || validate1 == null && check1 == null || !objstruct.GetAll().Any()) { if (ModelState.IsValid) { objstruct.Add(viewModel.CompanyCode, viewModel.CityCode, viewModel.CompanyName, viewModel.CityName); objstruct.Save(); RedirectToAction("StructureList", "Home"); TempData["SuccessMessage"] = "Structure Created"; } else { TempData["ErrorMessage"] = "Unable to Add"; } } else if (validate1 != null) { TempData["ErrorMessage"] = ("CompanyCode " + viewModel.CompanyCode + " with CityCode " + viewModel.CityCode + "Already Exists"); } else if (validate3 != null) { TempData["ErrorMessage"] = ("City Code " + viewModel.CityCode + " with City " + viewModel.CityName + " already Exists"); } else if (validate != null && validate1 != null && validate3 != null) { TempData["ErrorMessage"] = ("Company Code " + viewModel.CompanyCode + " with City Code " + viewModel.CityCode + "and" + viewModel.CityName + " Already Exists"); } else { TempData["ErrorMessage"] = ("City with Name " + viewModel.CityName + " already Exists in Company Code " + viewModel.CompanyCode + ""); } return(View(viewModel)); }
public ActionResult Login(tblUser model) { using (var context = new SqlContext()) { IUserRepository objrepo = new UserRepository(); IDepartmentRepository objdep = new DepartmentRepository(); IStructuredetailRepository objstruct = new StructuredetailRepository(); IEmployeeRepository objemp = new EmployeeRepository(); var isActive = objrepo.GetAll().Where(x => x.IsActive == 1) .Where(a => a.UserName == model.UserName && a.Password == model.Password).FirstOrDefault(); if (isActive != null) { var user = (from u in objrepo.GetAll() join d in objdep.GetAll() on u.DepartmentId equals d.DepartmentId join a in objrepo.GetAdmin() on u.AdminId equals a.AdminId join r in objstruct.Getroles() on u.RoleId equals r.Id join e in objemp.GetAll() on u.EmployeeId equals e.EmployeeId join s in objstruct.GetAll() on e.Id equals s.Id where u.UserName == model.UserName && u.Password == model.Password select new { u.UserName, u.UserId, d.DepartmentName, a.desc, r.RoleName, e.CompanyCode, s.CompanyName, e.CityCode, s.CityName, e.EmployeeName, e.PositionId, d.DepartmentId, e.EmployeeId }).FirstOrDefault(); if (user != null) { Session["UserName"] = user.UserName; Session["UserId"] = user.UserId; Session["DepartmentName"] = user.DepartmentName; Session["RoleName"] = user.RoleName; Session["isAdmin"] = user.desc; Session["CompanyName"] = user.CompanyName; Session["CityName"] = user.CityName; Session["CompanyCode"] = user.CompanyCode; Session["CityCode"] = user.CityCode; Session["Employeename"] = user.EmployeeName; Session["PositionId"] = user.PositionId; Session["DepartmentId"] = user.DepartmentId; Session["EmployeeId"] = user.EmployeeId; TempData["SuccessMessage"] = "Login Successfull"; return(RedirectToAction("Index", "Home")); } else { TempData["ErrorMessage"] = "Invalid UserName or Password"; } } else { TempData["ErrorMessage"] = "User is not Active.Please Login Again."; } return(View()); } }