public ActionResult Relation(long?tradeId) { try { var model = new RelationViewModel() { Relations = new List <Models.DomainModels.Relation>(), Trades = blTrade.Where(p => p.Status == "فعال").ToList(), TradeGroups = blTradeGroup.Where(p => p.Status == "فعال").ToList(), Users = blUser.Where(p => p.Status == "فعال" && p.Role.RoleName != "Admin" && p.Role.RoleName != "HoleBoss").ToList(), Roles = blRole.Where(p => p.Status == "فعال" && p.RoleName != "Admin" && p.RoleName != "HoleBoss").ToList(), Vehicles = blVehicle.Where(p => p.Status == "فعال").ToList(), VehicleGroups = blVehicleGroup.Where(p => p.Status == "فعال").ToList(), Colors = blColor.Select().ToList(), User = new User { Gender = true }, }; if (tradeId != null) { model.Trade = blTrade.Where(p => p.Id == tradeId).Single(); model.Relations = blRelation.Where(p => p.TradeId == tradeId).ToList(); } return(View(model)); } catch { return(RedirectToAction("Error404", "Home")); } }
public ActionResult Details() { try { var user = blUser.Where(p => p.Username == User.Identity.Name).Single(); bool isRelation = blRelation.Where(p => p.UserId == user.Id).Any(); if (!isRelation) { var model = new BossViewModel() { Trade = null }; return(View(model)); } else { var tradeId = blRelation.Where(p => p.UserId == user.Id).Single().TradeId; var model = new BossViewModel() { Trade = blTrade.Where(p => p.Id == tradeId).Single(), Relations = blRelation.Where(p => p.TradeId == tradeId && p.UserId != user.Id).ToList(), VehicleGroups = blVehicleGroup.Where(p => p.Status == "فعال").ToList(), Colors = blColor.Where(p => p.Status == "فعال").ToList(), User = new User() { Gender = true, Password = "******", ConfirmPassword = "******", RoleId = 5 } }; return(View(model)); } } catch { return(RedirectToAction("Error404", "Home")); } }