Example #1
0
        public async Task <IActionResult> StartRepair(int?Id)
        {
            if (Id == null)
            {
                return(NotFound());
            }



            var scheduleDetails = await _scheduleDetailRepository.GetScheduleDetailAsync(Id.Value);

            if (scheduleDetails == null)
            {
                return(NotFound());
            }


            var departments = _dealershipDepartmentRepository.GetDealershipDepartments(scheduleDetails.Dealership.Id);

            var model = _converterHelper.ToStartRepairViewModel(scheduleDetails, departments);


            return(View(model));
        }
        public async Task <IActionResult> Edit(Dealership dealership)
        {
            if (ModelState.IsValid)
            {
                var dShip = await _dealershipRepository.GetByIdAsync(dealership.Id);

                if (dealership.IsActive == true)
                {
                    try
                    {
                        var services = await _serviceRepository.GetAllServicesAsync();


                        foreach (var item in services)
                        {
                            await _servicesSuppliedRepository.AddServicesToDealershipAsync(item, dShip);
                        }


                        var departments = await _departmentRepository.GetDepartments();

                        foreach (var item in departments)
                        {
                            await _dealershipDepartmentRepository.AddDepartmentToDealershipAsync(item, dShip);
                        }

                        dShip.IsActive   = true;
                        dShip.UpdateDate = DateTime.Now;


                        var zipcode = await _zipCodeRepository.GetByIdAsync(dealership.ZipCodeId);

                        dShip.ZipCode = zipcode;
                        await _dealershipRepository.UpdateAsync(dShip);
                    }
                    catch (DbUpdateConcurrencyException)
                    {
                        if (!await _dealershipRepository.ExistsAsync(dealership.Id))
                        {
                            return(NotFound());
                        }
                        else
                        {
                            throw;
                        }
                    }
                    return(RedirectToAction(nameof(Index)));
                }
                else
                {
                    try
                    {
                        var departments = _dealershipDepartmentRepository.GetDealershipDepartments(dShip.Id);

                        await _dealershipDepartmentRepository.DeleteDEalershipDepartmentsAsync(departments);

                        var services = _servicesSuppliedRepository.GetWithServicesByDealershipId(dShip.Id);

                        await _dealershipServiceRepository.DeleteServicesFromDealershipAsync(services);


                        dShip.IsActive        = false;
                        dealership.UpdateDate = DateTime.Now;


                        var zipcode = await _zipCodeRepository.GetByIdAsync(dShip.ZipCodeId);

                        dShip.ZipCode = zipcode;
                        await _dealershipRepository.UpdateAsync(dShip);

                        return(RedirectToAction("Index"));
                    }
                    catch (DbUpdateConcurrencyException)
                    {
                        if (!await _dealershipRepository.ExistsAsync(dealership.Id))
                        {
                            return(NotFound());
                        }
                        else
                        {
                            throw;
                        }
                    }
                }
            }
            return(View(dealership));
        }