예제 #1
0
        public bool CreateCar(CarCreate model)
        {
            Member mem = new Member();

            using (var ctx = new ApplicationDbContext())
            {
                mem = ctx.Members.Single(e => e.MemberID == model.MemberID);
            }
            var entity = new Car()
            {
                OwnerID        = _userID,
                Make           = model.Make,
                VehicleModel   = model.VehicleModel,
                Specifications = model.Specifications,
                Description    = model.Description,
                MemberID       = model.MemberID,
                DisplayName    = $"{mem.FullName}, {model.Make}",
                CarCombine     = $"{model.Make} {model.VehicleModel}"
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Cars.Add(entity);
                return(ctx.SaveChanges() == 1);
            };
        }
예제 #2
0
 public IActionResult Create(CarCreate model)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest());
     }
     _carService.Create(model, User.FindFirst(ClaimTypes.NameIdentifier).Value);
     return(Ok());
 }
예제 #3
0
        public async Task <IHttpActionResult> PostAsync(CarCreate car)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            await CreateCarService().CreateACar(car);

            return(Ok(car));
        }
예제 #4
0
        public void Create(CarCreate model, string userId)
        {
            var entity = new Car
            {
                CarMakeId        = model.CarMakeId,
                CarModelId       = model.CarModelId,
                DateOfProduction = model.DateOfProduction,
                Price            = model.Price,
                Country          = model.Country,
                UserId           = userId
            };

            _dbContext.Cars.Add(entity);
            _dbContext.SaveChanges();
        }
        public IHttpActionResult Post(CarCreate car)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var service = CreateCarService();

            if (!service.CreateCar(car))
            {
                return(InternalServerError());
            }

            return(Ok());
        }
예제 #6
0
        public bool CreateCar(CarCreate model)
        {
            var entity =
                new Car()
            {
                OwnerID   = _userID,
                CarName   = model.CarName,
                CarColor  = model.CarColor,
                CarRarity = model.CarRarity
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Cars.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
예제 #7
0
        private void button1_Click(object sender, RoutedEventArgs e)
        {
            ICar car = CarCreate.Create((Cars)comboBox3.SelectedValue);

            if (car == null)
            {
                this.Close();
            }

            car.Body();
            car.Brush((ConsoleColor)comboBox1.SelectedValue);

            car.Doors(Convert.ToInt32(comboBox2.SelectedValue));
            car.Tyres();

            MessageBox.Show(car.ToString());
        }
예제 #8
0
        public ActionResult CreatePost([Bind(Prefix = "id")] int?customerId, string returnUrl)
        {
            var viewModel = new CarCreate
            {
                Customers = _customerService.Customers.Select(n => new SelectListItem
                {
                    Value = n.Id.ToString(),
                    Text  = string.Format("{0} {1}", n.Name, n.Surname)
                }),
                ReturnUrl = returnUrl
            };

            if (customerId.HasValue)
            {
                viewModel.CustomerId = customerId.Value;
            }

            if (!TryUpdateModel(viewModel) || !ModelState.IsValid)
            {
                return(View(viewModel));
            }

            try
            {
                var model = viewModel.ToCar();
                _carService.Create(model);
                //Session["CarCreateSessionKey"] = new List<int>() { customerId.Value, model.Id };
                if (customerId.HasValue)
                {
                    Session["CarCreateSessionKey"] = new List <KeyValuePair <string, int> >()
                    {
                        new KeyValuePair <string, int>("Customer", customerId.Value),
                        new KeyValuePair <string, int>("Car", model.Id)
                    };
                }
            }
            catch (Exception ex)
            {
                return(View(viewModel));

                throw ex;
            }

            return(Redirect(returnUrl));
        }
예제 #9
0
        public HttpResponseMessage CarCreate(CarCreate request)
        {
            CarsService carsService = new CarsService();

            if (request == null)
            {
                ModelState.AddModelError("", "missing model");
            }

            if (!ModelState.IsValid)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }

            var id = carsService.CarCreate(request);

            return(Request.CreateResponse(HttpStatusCode.Created, id));
        }
예제 #10
0
        public ActionResult Create([Bind(Prefix = "id")] int?customerId, string returnUrl)
        {
            var viewModel = new CarCreate
            {
                Customers = _customerService.Customers.Select(n => new SelectListItem
                {
                    Value = n.Id.ToString(),
                    Text  = string.Format("{0} {1}", n.Name, n.Surname)
                }),
                ReturnUrl = returnUrl
            };

            if (customerId.HasValue)
            {
                viewModel.CustomerId = customerId.Value;
            }

            return(View(viewModel));
        }
예제 #11
0
        public IHttpActionResult AddCar(CarCreate car)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (car.PlateNumber == "ABC-123")
            {
                return(Conflict());
            }

            return(Ok(new Car
            {
                Id = 2,
                PlateNumber = car.PlateNumber,
                Color = car.Color
            }));
        }
        public ActionResult Create(CarCreate model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var service = CreateCarService();

            if (service.CreateCar(model))
            {
                TempData["SaveResult"] = "Your car was created.";
                return(RedirectToAction("Index"));
            }
            ;

            ModelState.AddModelError("", "Car could not be created.");

            return(View(model));
        }
예제 #13
0
        public ActionResult Create(CarCreate model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var serviceCar = CreateCarService();

            if (serviceCar.CreateCar(model))
            {
                TempData["SaveResult"] = "Your Car Was Created!";
                return(RedirectToAction("Index"));
            }

            ModelState.AddModelError("", "Car Could Not Be Created.");

            ViewBag.MemberID = new SelectList(serviceCar.GetMemberList(), "MemberID", "FullName", model.MemberID);
            return(View(model));
        }
예제 #14
0
        // ========= Create =========//
        public int CarCreate(CarCreate request)
        {
            using (SqlConnection con = new SqlConnection("Server=den1.mssql5.gear.host;Database=carstest;User Id=carstest;Password=Hy19Ks!-Kom3"))
            {
                con.Open();
                SqlCommand cmd = con.CreateCommand();
                cmd.CommandText = "cars_create";
                cmd.CommandType = System.Data.CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@Make", request.Make);
                cmd.Parameters.AddWithValue("@Model", request.Model);
                cmd.Parameters.AddWithValue("@Year", request.Year);
                cmd.Parameters.AddWithValue("@Color", request.Color);

                var idParam = cmd.Parameters.Add("@id", SqlDbType.Int);
                idParam.Direction = ParameterDirection.Output;

                cmd.ExecuteNonQuery();

                return((int)idParam.Value);
            }
        }
예제 #15
0
        public async Task <bool> CreateACar(CarCreate model)
        {
            var entity = new Car()
            {
                OwnerID        = _userId,
                ManufacturerId = model.ManufacturerId,
                GarageId       = model.GarageId,
                Make           = model.Make,
                Model          = model.Model,
                Year           = model.Year,
                CarType        = model.CarType,
                Transmission   = model.Transmission,
                CarValue       = model.CarValue
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Cars.Add(entity);
                return(await ctx.SaveChangesAsync() == 1);
            }
        }
예제 #16
0
        static void UserMenu(Project proj, User user, CreateProject createProject)
        {
start:
            Console.Clear();
            Console.WriteLine("1 - Машина\n2 - Компонент\n3 - Останов");
            Int32.TryParse(Console.ReadLine(), out int userChoice);
            switch (userChoice)
            {
            case 1:
            {
                Console.Clear();
                Console.WriteLine("------------------------Контроль технического обслуживания машин-------------------------");
                Console.WriteLine("1 - Отображение всего парка машин на проекте\n" +
                                  "2 - Поиск машины по его гаражному номеру и модели\n" +
                                  "3 - Сделать останов машины\n" +
                                  "4 - Прикрепить компонент к машине\n" +
                                  "5 - Сделать машину активной/неактивной\n" +
                                  "6 - Создать машину");
                Console.WriteLine("Вернуться в меню - enter x2");
                Int32.TryParse(Console.ReadLine(), out int choice);
                switch (choice)
                {
                case 1:
                {
                    createProject.ShowAllCarsInProject(ref proj);
                    Console.WriteLine("Вернуться в меню - enter");
                    if (Console.ReadKey().Key == ConsoleKey.Enter)
                    {
                        goto start;
                    }
                    break;
                }

                case 2:
                {
                    SearchCar(ref proj);
                    Console.WriteLine("Вернуться в меню - enter");
                    if (Console.ReadKey().Key == ConsoleKey.Enter)
                    {
                        goto start;
                    }

                    break;
                }

                case 3:
                {
                    Car car = SearchCarForStop(ref proj);
                    if (car != null)
                    {
                        if (createProject.IsBroken(ref car))
                        {
                            Console.WriteLine("Машина уже не в рабочем состоянии");
                        }
                        else
                        {
                            createProject.CreateBreaks(ref car, ref proj, ref user);
                        }
                    }
                    else
                    {
                        Console.WriteLine("Проверьте корректность ввода");
                    }

                    Console.WriteLine("Вернуться в меню - enter");
                    if (Console.ReadKey().Key == ConsoleKey.Enter)
                    {
                        goto start;
                    }
                    break;
                }

                case 4:
                {
                    Car car = SearchCar(ref proj);
                    if (car != null)
                    {
                        if (CarCreate.IsComponentInThatCar(ref car, out int id))
                        {
                            Console.WriteLine("Компонент уже есть в данной машине");
                            Console.WriteLine("Создать новый компонент 1 - да Любая клавиша - выход в меню");
                            Int32.TryParse(Console.ReadLine(), out int ch);
                            if (ch == 1)
                            {
                                Console.WriteLine("Введите id компонента");
                                Int32.TryParse(Console.ReadLine(), out id);
                                Part component = CreateComponent.CtComponent(id);
                                CarCreate.AttachComponentToCar(ref car, ref component, out string message);
                                Console.WriteLine(message);
                            }
                            else
                            {
                                goto start;
                            }
                        }
                        else
                        {
                            Part component = CreateComponent.CtComponent(id);
                            CarCreate.AttachComponentToCar(ref car, ref component, out string message);
                            Console.WriteLine(message);
                        }
                    }
                    else
                    {
                        Console.WriteLine("Проверьте корректность ввода");
                    }

                    Console.WriteLine("Вернуться в меню - enter");
                    if (Console.ReadKey().Key == ConsoleKey.Enter)
                    {
                        goto start;
                    }
                    break;
                }

                case 5:
                {
                    Car car = SearchCar(ref proj);
                    if (car != null)
                    {
                        Console.WriteLine("1 - Активной 2 - Неактивной");


                        Int32.TryParse(Console.ReadLine(), out int v);
                        switch (v)
                        {
                        case 1:
                        {
                            CarCreate.GetCarActiveOrNot(ref car, true);
                            Console.WriteLine("Машина активна");
                            break;
                        }

                        case 2:
                        {
                            CarCreate.GetCarActiveOrNot(ref car, false);
                            Console.WriteLine("Машина неактивна");
                            break;
                        }
                        }
                    }
                    else
                    {
                        Console.WriteLine("Проверьте корректность ввода");
                    }

                    Console.WriteLine("Вернуться в меню - enter");
                    if (Console.ReadKey().Key == ConsoleKey.Enter)
                    {
                        goto start;
                    }

                    break;
                }

                case 6:
                {
                    CarCreate.CreateCar(ref proj);
                    Console.WriteLine("Машина добавлена в список машин на проекте");

                    Console.WriteLine("Вернуться в меню - enter");
                    if (Console.ReadKey().Key == ConsoleKey.Enter)
                    {
                        goto start;
                    }
                    break;
                }
                }
                if (Console.ReadKey().Key == ConsoleKey.Enter)
                {
                    goto start;
                }
                break;
            }