public ActionResult DriverRegister1(DriverRegisterViewModel newDriver)
        {
            Driver driver;
            bool   result = false;

            try
            {
                driver            = new Driver();
                driver.FirstName  = newDriver.FirstName;
                driver.Lastname   = newDriver.LastName;
                driver.TC         = newDriver.TC;
                driver.BirthDate  = newDriver.BirthDate;
                driver.BirthPlace = newDriver.BirthPlace;
                driver.Phone      = newDriver.Phone;
                driver.EMail      = newDriver.EMail;
                Admin admin = Session["admin"] as Admin;
                driver.CompanyID = admin.CompanyID;
                result           = _driverService.Add(driver);
            }
            catch (Exception)
            {
                ViewBag.result = "Bir Hata Oluştu";
            }

            if (result)
            {
                ViewBag.result = "Sürücü Kaydı Başarılı Bir Şekilde Oluşturuldu";
            }
            else
            {
                ViewBag.result = "Kayıt Oluşturulurken Bir Hata Oluştu";
            }
            return(View());
        }
示例#2
0
        public HttpResponseMessage Create(HttpRequestMessage request, DriverViewModel driverVm)
        {
            return(CreateHttpResponse(request, () =>
            {
                HttpResponseMessage response = null;
                if (!ModelState.IsValid)
                {
                    response = request.CreateResponse(HttpStatusCode.BadRequest, ModelState);
                }
                else
                {
                    var newDriver = new Driver();
                    newDriver.UpdateDriver(driverVm);
                    newDriver.CreatedDate = DateTime.Now;

                    _driverService.Add(newDriver);
                    _driverService.Save();

                    var responseData = Mapper.Map <Driver, DriverViewModel>(newDriver);
                    response = request.CreateResponse(HttpStatusCode.Created, responseData);
                }

                return response;
            }));
        }
        public async Task <ActionResult <Driver> > Post(Driver driver)
        {
            try
            {
                await _driverService.Add(driver);

                return(Ok(driver));
            }
            catch (Exception ex)
            {
                _logger.LogError($"Exception: {ex.Message}");
                return(BadRequest());
            }
        }
 public async Task <ActionResult> Create(DriverViewModel driverViewModel)
 {
     try
     {
         var driver = _mapper.Map <Driver>(driverViewModel);
         if (await _driverService.UniquenessCheck(driver))
         {
             await _driverService.Add(driver);
         }
         return(RedirectToAction(nameof(Drivers)));
     }
     catch (Exception exception)
     {
         _logger.LogError($"Driver create error:{exception.Message}");
         return(View(driverViewModel));
     }
 }
        public override void ExecuteSaveCommand(object obj)
        {
            if (mViewModel.EditingDriver == null)
            {
                ShowMessage("Es gibt nichts zu speichern.");
                return;
            }

            if (mViewModel.EditingDriver.EmployeeNumber <= 0)
            {
                ShowMessage("Die Personal-Nr. muss größer als 0 sein.");
                return;
            }

            if (mViewModel.EditingDriver.FirstName == "")
            {
                ShowMessage("Bitte geben Sie einen Vornamen ein.");
                return;
            }

            if (mViewModel.EditingDriver.LastName == "")
            {
                ShowMessage("Bitte geben Sie einen Nachamen ein.");
                return;
            }

            int updateResult = 1;

            if (mViewModel.EditingDriver.Id == 0)
            {
                updateResult = mDriverService.Add(mViewModel.EditingDriver) ? 0 : 1;
            }
            else
            {
                updateResult = mDriverService.UpdateDriver(mViewModel.EditingDriver.Id, mViewModel.EditingDriver);
            }

            HandleUpdateResult(updateResult);
        }
        public async Task StartMenu()
        {
            while (true)
            {
                PrintMenu();
                int.TryParse(Console.ReadLine(), out int menuNumber);
                switch (menuNumber)
                {
                case (int)AdminsDriverMenu.AllDriver:
                {
                    ShowDrivers(await _driverProcessing.GetAll());
                }
                break;

                case (int)AdminsDriverMenu.AddDriver:
                {
                    var       driver       = CreateDriver();
                    var       validResults = driver.IsValid();
                    const int NoError      = 0;
                    if (validResults.Count() != NoError)
                    {
                        foreach (var result in validResults)
                        {
                            Console.WriteLine(result.ErrorMessage);
                        }
                    }
                    else
                    {
                        if (await _driverProcessing.UniquenessCheck(driver))
                        {
                            await _driverProcessing.Add(driver);

                            Console.WriteLine("Success");
                        }
                        else
                        {
                            Console.WriteLine("This driver is already on the list");
                        }
                    }
                    Console.ReadKey();
                }
                break;

                case (int)AdminsDriverMenu.DeleteDriver:
                {
                    Console.WriteLine("Enter driver id");

                    try
                    {
                        await _driverProcessing.Delete(ConsoleHelper.EnterNumber());

                        Console.WriteLine("Delete is sucessfull");
                    }
                    catch (NullReferenceException exception)
                    {
                        _logger.Error($"Not found:{exception.Message}");
                        Console.WriteLine("Driver is not find");
                    }
                    catch (DbException exception)
                    {
                        _logger.Error($"Failed to remove:{exception.Message}");
                        Console.WriteLine("Find error");
                    }

                    Console.ReadKey();
                }
                break;

                case (int)AdminsDriverMenu.UpdateDriver:
                {
                }
                break;

                case (int)AdminsDriverMenu.Find:
                {
                    Console.Clear();
                    Console.WriteLine("Enter licence number:");
                    var driver = await _driverProcessing.FindByDriverLicenseNumber(Console.ReadLine());

                    if (driver == null)
                    {
                        Console.WriteLine("Licence number not find");
                    }
                    else
                    {
                        Console.WriteLine($"Surname | Name | Patronymic | Call sign | DriverLicenseNumber | Date of issue of drivers license | Is on holiday | Is sick leave");
                        Console.WriteLine($"{driver.Surname} | {driver.Name} | {driver.Patronymic} | {driver.CallSign} | {driver.DriverLicenseNumber} | {driver.DateOfIssueOfDriversLicense} | {driver.IsOnHoliday} | {driver.IsSickLeave}");
                    }
                    Console.ReadKey();
                }
                break;

                case (int)AdminsDriverMenu.GiveCar:
                {
                    Console.Clear();
                    Console.WriteLine("Enter car id");
                    var carId = ConsoleHelper.EnterNumber();
                    if (await _carProcessing.FindById(carId) != null)
                    {
                        Console.WriteLine("Enter driver id");
                        var driverId = ConsoleHelper.EnterNumber();
                        if (_driverProcessing.FindById(driverId) != null)
                        {
                            try
                            {
                                await _driverProcessing.GiveCar(driverId, carId);

                                Console.WriteLine("Sucessfull");
                            }
                            catch (DbUpdateException exception)
                            {
                                _logger.Error($"Update error:{exception.Message}");
                                Console.WriteLine("This car is use");
                            }
                            catch (Exception)
                            {
                                Console.WriteLine("Update error");
                            }
                        }
                        else
                        {
                            Console.WriteLine("Driver not find");
                        }
                    }
                    else
                    {
                        Console.WriteLine("Car not find");
                    }
                    Console.ReadKey();
                }
                break;

                case (int)AdminsDriverMenu.AdminMenu:
                {
                    return;
                }

                default:
                {
                    Console.Clear();
                    Console.WriteLine("Incorrect number");
                }
                break;
                }
            }
        }