public async Task <IActionResult> AssignShopTech(TechnicianModel model) { AssignedTechDb assignTech = new AssignedTechDb { TechnicianId = _repo.GetShopTeches.Where(name => name.TechnicianName.Equals(model.TechName) && name.UserId.Equals(int.Parse(Request.Cookies["UserID"]))).FirstOrDefault().TechnicianId, ServiceId = _repo.GetShopServices.Where(name => name.ServiceName.Equals(model.AssignedService) && name.UserId.Equals(int.Parse(Request.Cookies["UserID"]))).FirstOrDefault().ServiceId }; bool result = await _repo.CreateAssignedTech(assignTech); if (result) { ViewBag.AssignedTechSucess = $"{model.AssignedService} Services Added to {model.TechName}"; } else { ModelState.AddModelError(string.Empty, "Couldn't Add Shop Services. Try Again With Cookies Enabled"); } return(View(new TechnicianModel { ShopServices = _repo.GetShopServices.Where(s => s.UserId.Equals(int.Parse(Request.Cookies["UserID"]))), TechDbs = _repo.GetShopTeches.Where(s => s.UserId.Equals(int.Parse(Request.Cookies["UserID"]))), UserCookie = Request.Cookies["UserID"] })); }
public async Task <bool> CreateAssignedTech(AssignedTechDb assignedTech) { await context.AddAsync(assignedTech); await context.SaveChangesAsync(); return(await Task.FromResult(true)); }
public async Task <IActionResult> CreateTechnician(TechnicianModel technicianModel) { //if (ModelState.IsValid) //{ ShopTechDb techDb = new ShopTechDb { UserId = int.Parse(Request.Cookies["UserID"]), TechnicianName = technicianModel.TechnicianName, TechnicianDescription = technicianModel.TechnicianDescription }; bool result = await _repo.CreateShopTeches(techDb); if (result) { // var service = _repo.GetShopServices.Where(name => name.ServiceName.Equals(technicianModel.AssignedService)).FirstOrDefault(); AssignedTechDb assignedTech = new AssignedTechDb { TechnicianId = techDb.TechnicianId, ServiceId = _repo.GetShopServices.Where(name => name.ServiceName.Equals(technicianModel.AssignedService) && name.UserId.Equals(int.Parse(Request.Cookies["UserID"]))).FirstOrDefault().ServiceId }; bool result1 = await _repo.CreateAssignedTech(assignedTech); if (result1) { ViewBag.TechSuccess = $"{technicianModel.TechnicianName} is Added and Assigned to {technicianModel.AssignedService}"; } else { ModelState.AddModelError(string.Empty, "Couldn't Add Shop Services. Try Again With Cookies Enabled"); } } else { ModelState.AddModelError(string.Empty, "Couldn't Add Shop Services. Try Again With Cookies Enabled"); } // } return(View(new TechnicianModel { ShopServices = _repo.GetShopServices.Where(s => s.UserId.Equals(int.Parse(Request.Cookies["UserID"]))) })); }