示例#1
0
        public async Task <bool> CreateVehReq(VehReqDb vehReq)
        {
            await context.AddAsync(vehReq);

            await context.SaveChangesAsync();

            return(await Task.FromResult(true));
        }
        public async Task<IActionResult> CheckBoxTester(VehicleReqModel model, string[] Blanks, [FromQuery(Name = "vehID")] string vehicleID, [FromQuery(Name = "shopID")] string shopsID)
        {
            if (ModelState.IsValid)
            {
                VehReqDb vehReq = new VehReqDb
                {
                    VehicleId = int.Parse(vehicleID),
                    VehReqName = model.VehReqName,
                    VehReqDate = model.VehdateTime,
                    UserId = int.Parse(shopsID),
                    VehReqMessage = model.VehMessage
                };

                bool result = await _repo.CreateVehReq(vehReq);

                if (result)
                {

                    //string servicereqAdded = String.Empty;

                    bool reload_error = false;

                    foreach (var ite in Blanks)
                    {
                        ServiceReqDb serviceReq = new ServiceReqDb
                        {
                            VehReqId = vehReq.VehReqId,
                            AssignId = int.Parse(ite)
                        };

                        reload_error = await _repo.CreateServiceReq(serviceReq);

                        //if (reload_error)
                        //{
                        //    servicereqAdded += $"{ite}\t";
                        //}

                    }

                    //reload = true;

                    if (reload_error)
                    {
                        ViewBag.RequestSent = "Vehicle Request Service Sent";
                    }
                    else
                    {
                        ModelState.AddModelError(string.Empty, "Couldn't Add Shop Services. Try Again With Cookies Enabled");
                    }

                }
            }

            var user = new VehicleReqModel
            {
                GetUser = _repo.GetUserDbs.Where(s => s.UserId.Equals(int.Parse(shopsID))).FirstOrDefault(),
                AssignedTeches = _repo.GetAssignedTechDbs.Include(se => se.Service).Where(id => id.Service.UserId.Equals(int.Parse(shopsID))).Include(st => st.Technician).Where(ids => ids.Technician.UserId.Equals(int.Parse(shopsID))),
                VehicleID = int.Parse(vehicleID),
                ShopServices = _repo.GetShopServices.Include(sp => sp.AssignedTechDb).ThenInclude(ap => ap.Technician).Where(ids => ids.UserId.Equals(int.Parse(shopsID))),
                UserID = int.Parse(shopsID)
            };


            return View("VehReqs", user);
        }