public async Task <bool> CreateShopTeches(ShopTechDb shopTeches) { await context.AddAsync(shopTeches); 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"]))) })); }