Exemplo n.º 1
0
        public async Task <ActionResult> PostCarItem(
            [FromForm] CarRequest carRequest)
        {
            var car = _customMapper.CarRequestToCar(carRequest);

            ClaimsPrincipal claimsPrincipalCurrentUser;
            var             userId = string.Empty;

            if (carRequest.Token != string.Empty)
            {
                claimsPrincipalCurrentUser = _carService.GetClaimsPrincipal(carRequest.Token);
                userId = claimsPrincipalCurrentUser.Claims.Single(x => x.Type == "id").Value;
            }


            car.ImgPath = await CreateImgFromRequest(Request, carRequest);

            var createResult = await _carService.Create(car, userId);//changes entity state to added and execute save changes that produces insert command

            if (createResult)
            {
                var locationUri = _uriService.GetVehicleUri(car.Id.ToString());
                return(Created(locationUri, new Response <CarResponse>(
                                   _customMapper.CarToCarResponse(car))));
            }
            return(Ok("Something went wrong"));
        }
Exemplo n.º 2
0
        public override Task <CarReply> GetCar(CarRequest request, Grpc.Core.ServerCallContext context)
        {
            var r = new CarReply();
            var f = r.Documents;

            return(base.GetCar(request, context));
        }
Exemplo n.º 3
0
        Put(int?id, [FromForm] CarRequest carRequest)
        {
            if (id != carRequest.Id)
            {
                return(BadRequest());
            }

            //TODO:
            //test

            if (!await CheckIsUserAuthorizedForAction(carRequest.Id, carRequest.Token))
            {
                return(BadRequest("You have not enough permissions for this action"));
            }

            var car    = _customMapper.CarRequestToCar(carRequest);
            var oldCar = await _carService.GetById(id);

            _vehicleImageRetriever.DeleteFile(oldCar.ImgPath);

            car.ImgPath = await CreateImgFromRequest(Request, carRequest);


            var updatedNums = await _carService.Update(car);

            if (updatedNums > 0)
            {
                return(Ok(new Response <string>
                              ($"Car with id {carRequest.Id} and unique number " +
                              $"{carRequest.UniqueNumber} successfully updated")));
            }

            return(NoContent());
        }
Exemplo n.º 4
0
        public void DeleteCar(CarRequest request)
        {
            if (request.LicenseKey != "secret")
            {
                throw new WebFaultException <string>("Wrong licese key", HttpStatusCode.Forbidden);
            }
            else
            {
                string cs = ConfigurationManager.ConnectionStrings["CRCS"].ConnectionString;

                using (SqlConnection con = new SqlConnection(cs))
                {
                    SqlCommand cmd = new SqlCommand("spDeleteCar", con);
                    cmd.CommandType = CommandType.StoredProcedure;

                    SqlParameter parameterId = new SqlParameter();
                    parameterId.ParameterName = "@Id";
                    parameterId.Value         = request.CarId;

                    cmd.Parameters.Add(parameterId);

                    con.Open();
                    cmd.ExecuteNonQuery();
                }
            }
        }
        public async Task <string> SendMessage(CarRequest carRequest)
        {
            var key = Guid.NewGuid().ToString();

            var carObjectMessage = JsonConvert.SerializeObject(carRequest);

            var config = new ProducerConfig
            {
                BootstrapServers      = "localhost:9092",
                MessageTimeoutMs      = 5000,
                MessageSendMaxRetries = 5
            };

            ProducerBuilder <string, string> kafkaProducer = new ProducerBuilder <string, string>(config);

            using (var producer = kafkaProducer.Build())
            {
                try
                {
                    var sendResult = producer.ProduceAsync("kafka-topic",
                                                           new Message <string, string> {
                        Key = key, Value = carObjectMessage
                    }).GetAwaiter().GetResult();

                    await Task.Delay(100);

                    return(key);
                }

                catch (ProduceException <string, string> e)
                {
                    return($"Delivery messaging failed: {e.Error.Reason}");
                }
            }
        }
        public async Task <IActionResult> PutCarRequest(long id, CarRequest carRequest)
        {
            if (id != carRequest.RequestNumber)
            {
                return(BadRequest());
            }

            _context.Entry(carRequest).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CarRequestExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <ActionResult <CarRequest> > PostCarRequest(CarRequest carRequest)
        {
            _context.CarRequsets.Add(carRequest);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetCarRequest", new { id = carRequest.RequestNumber }, carRequest));
        }
Exemplo n.º 8
0
        public ActionResult Post([FromBody] CarRequest request)
        {
            if (request.CarId == null || request.CarNumber == null || request.PhoneNumber == null ||
                request.IsActive == null)
            {
                return(BadRequest());
            }

            var convertedCarRequest = new CarRequest()
            {
                CarId       = request.CarId,
                CarNumber   = request.CarNumber,
                PhoneNumber = request.PhoneNumber,
                IsActive    = request.IsActive
            };

            try
            {
                DBConnector db = new DBConnector();
                db.InsertNewCar(convertedCarRequest);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                return(StatusCode(500));
            }
            return(Ok());
        }
Exemplo n.º 9
0
        public IActionResult DeleteCar([FromBody] CarRequest carRequest)
        {
            var car = _mapper.Map <Car>(carRequest);

            _carServices.Remove(car);
            return(Ok());
        }
Exemplo n.º 10
0
        public JsonResult SaveCarRequest(CarRequestModel Data, DateTime dateData)
        {
            var resultModel = new JsonResultModel <CarRequest>();

            try
            {
                using (DataService db = new DataService())
                {
                    var cookie = HttpContext.Request.Cookies[FormsAuthentication.FormsCookieName];
                    var ticket = FormsAuthentication.Decrypt(cookie.Value);
                    var gCode  = Guid.Parse(ticket.UserData);

                    var item = new CarRequest();
                    var user = db.Context.Membership_User.FirstOrDefault(x => x.UserCode == gCode);
                    item.EmployeID   = user.ID;
                    item.Date        = dateData;
                    item.CarID       = Data.ID;
                    item.RequestDate = DateTime.Now;

                    db.Context.CarRequests.Add(item);

                    db.Context.SaveChanges();
                    resultModel.Status  = JsonResultType.Success;
                    resultModel.Message = "Form Başarıyla kaydedildi. İyi çalışmalar :=) ";
                }
            }
            catch (Exception ex)
            {
                resultModel.Status  = JsonResultType.Error;
                resultModel.Message = "Rapor Gönderilemedi Tekrar Deneyiniz???!!!!!";
            }

            return(Json(resultModel, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 11
0
        public ActionResult Post([FromBody] CarRequest request)
        {
            CarsService carsService = new CarsService();

            return(carsService.Post(request));
            // if (request.CarId == null || request.CarNumber == null || request.PhoneNumber == null ||
            //     request.IsActive == null)
            // {
            //     return BadRequest();
            // }

            // var convertedCarRequest = new CarRequest()
            // {
            //     CarId = request.CarId,
            //     CarNumber = request.CarNumber,
            //     PhoneNumber = request.PhoneNumber,
            //     IsActive = request.IsActive
            // };

            // try
            // {
            //     DBConnector db = new DBConnector();
            //     db.InsertNewCar(convertedCarRequest);
            // }
            // catch (Exception ex)
            // {
            //     Console.WriteLine(ex);
            //     return StatusCode(500);
            // }
            // return Ok();
        }
Exemplo n.º 12
0
        public IActionResult PutCar(Guid id, [FromBody] CarRequest request)
        {
            var exists = cars.Any(c => c.Id == id);

            if (exists)
            {
                var requestError = IsRequestValid(request);

                if (requestError == null)
                {
                    var car = cars.Find(c => c.Id.Equals(id));
                    car.Make         = request.Make;
                    car.Model        = request.Model;
                    car.Registration = request.Registration;

                    return(Ok(car));
                }
                else
                {
                    return(requestError);
                }
            }
            else
            {
                return(NotFound());
            }
        }
Exemplo n.º 13
0
        private CarInfo GetCarInfoIfValidInput(HtmlInputText id)
        {
            if (CheckIfTextFieldIsNotEmpty(id))
            {
                CarRequest request = new CarRequest();

                request.LicenseKey = txtLicenseKey.Text;
                request.CarId      = Convert.ToInt32(txtId.Value);

                try
                {
                    CarInfo car = client.GetCarInfo(request);
                    txtBrand.Value   = car.Brand;
                    txtManYear.Value = car.ManufacturingYear.ToString();
                    txtModel.Value   = car.Model;
                    txtRegNr.Value   = car.RegistrationNumber;
                    return(car);
                }
                catch (FaultException ex)
                {
                    lblMessageDelete.Text = ex.Message;
                    return(null);
                }
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 14
0
        public async Task <ActionResult> Index()
        {
            string json = await ASP_Finally.Models.CarRequest.GetPostID();

            var o = JObject.Parse(json);

            foreach (var item in o)
            {
                if (item.Key == "result")
                {
                    foreach (var id in item.Value["search_result"]["ids"])
                    {
                        announcements.Add(new Announcement(id.ToString()));
                        announcements.Last().PhotoData.Add(await CarRequest.GetPostFirstInfo(announcements.Last().ID.ToString(), announcements));
                        announcements.Last().LocationCityName = id.ToString();

                        Announcement tmpAnn = await CarRequest.GetAllInfo(id.ToString());

                        announcements.Last().LocationCityName = tmpAnn.LocationCityName;
                        announcements.Last().NameCar          = tmpAnn.NameCar;
                        announcements.Last().Phone            = tmpAnn.Phone;
                        announcements.Last().USD         = tmpAnn.USD;
                        announcements.Last().Description = tmpAnn.Description;
                    }
                    break;
                }
            }

            return(View(announcements));
        }
Exemplo n.º 15
0
        private async Task <string> CreateImgFromRequest(HttpRequest request, CarRequest carRequest)
        {
            if (request == null)
            {
                return(string.Empty);
            }

            var formCollection = await request.ReadFormAsync();

            var ImgFile = formCollection.Files.First();

            if (ImgFile != null && ImgFile.Length > 0)
            {
                var createdImgPathResult = await _vehicleImageRetriever
                                           .CreateImgByBrandAndUniqueNumber(
                    ImgFile,
                    carRequest.Brand,
                    carRequest.UniqueNumber,
                    _imgDirectory);

                if (createdImgPathResult != string.Empty)
                {
                    _logger.LogInformation($"{ImgFile.FileName} created successfully");
                    return(createdImgPathResult);
                }
                else
                {
                    _logger.LogInformation($"{ImgFile.FileName} not created");
                }
            }
            return(string.Empty);
        }
Exemplo n.º 16
0
        public ICollection <CarRequest> GetCarRequest()
        {
            List <CarRequest> cars     = new List <CarRequest>();
            string            filePath = "C:\\AUTOS.xlsx";
            FileInfo          fileInfo = new FileInfo(filePath);

            using (ExcelPackage excelPackage = new ExcelPackage(fileInfo))
            {
                ExcelWorksheet worksheet  = excelPackage.Workbook.Worksheets.FirstOrDefault();
                int            totalColum = worksheet.Dimension.End.Column;
                int            totalRow   = worksheet.Dimension.End.Row;

                for (int row = 2; row <= totalRow; row++)
                {
                    CarRequest car = new CarRequest();
                    for (int col = 1; col <= totalColum; col++)
                    {
                        if (col == 1)
                        {
                            car.Amis = worksheet.Cells[row, col].Value.ToString();
                        }

                        if (col == 2)
                        {
                            car.Marca = worksheet.Cells[row, col].Value.ToString();
                        }

                        if (col == 3)
                        {
                            car.Tipo = worksheet.Cells[row, col].Value.ToString();
                        }

                        if (col == 4)
                        {
                            car.Descripcion = worksheet.Cells[row, col].Value.ToString();
                        }

                        if (col == 5)
                        {
                            car.Modelo = worksheet.Cells[row, col].Value.ToString();
                        }

                        if (col == 6)
                        {
                            car.Bucket = worksheet.Cells[row, col].Value.ToString();
                        }

                        if (col == 7)
                        {
                            car.LoJack = worksheet.Cells[row, col].Value.ToString();
                        }
                    }

                    cars.Add(car);
                }
            }

            return(cars);
        }
Exemplo n.º 17
0
        public static Car Map(CarRequest carRequest)
        {
            var config = new MapperConfiguration(cfg => { cfg.CreateMap <CarRequest, Car>(); });

            var mapper = config.CreateMapper();

            return(mapper.Map <CarRequest, Car>(carRequest));
        }
Exemplo n.º 18
0
        public ActionResult DeleteConfirmed(int id)
        {
            CarRequest carRequest = db.CarRequests.Find(id);

            db.CarRequests.Remove(carRequest);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Exemplo n.º 19
0
        public void AddCar(CarRequest carRequest)
        {
            var car  = CarRequestToModel.Map(carRequest);
            var guid = Guid.NewGuid();

            car.Id = guid;
            _db.Add(car.Id, car);
        }
        public async Task <IActionResult> SendCar([FromBody] CarRequest carRequest)
        {
            var result = await Task.Run(() => kafkaService.SendMessage(carRequest));

            return(result.Contains("failed") ? StatusCode(400, new CarResponse()) : StatusCode(201, new CarResponse {
                id = result
            }));
        }
Exemplo n.º 21
0
        public IActionResult AddCar([FromBody] CarRequest carRequest)
        {
            var car = _mapper.Map <Car>(carRequest);

            _carServices.Add(car);
            var carResponse = _mapper.Map <CarResponse>(car);

            return(Ok(carResponse));
        }
Exemplo n.º 22
0
        public CarInfo DropOffCar(CarRequest request)
        {
            LicenseCheck(request.LicenseKey, 1);

            CarInfo carInfo = new CarInfo(carMethods.DropOff(request.CarId));

            carInfo.LicenseKey = request.LicenseKey;

            return(carInfo);
        }
Exemplo n.º 23
0
        public CarInfo PickUpCar(CarRequest request)
        {
            LicenseCheck(request.LicenseKey, 1);

            CarInfo carInfo = new CarInfo(carMethods.PickUp(request.CarId));

            carInfo.LicenseKey = request.LicenseKey;

            return(carInfo);
        }
Exemplo n.º 24
0
        private Car CreateCar(CarRequest request)
        {
            Car car = new Car();

            car.Id           = Guid.NewGuid();
            car.ClientId     = request.ClientId;
            car.Make         = request.Make;
            car.Model        = request.Model;
            car.Registration = request.Registration;
            return(car);
        }
Exemplo n.º 25
0
 public ActionResult Edit([Bind(Include = "ID,CarID,Price,CustomerID,BrokerID")] CarRequest carRequest)
 {
     if (ModelState.IsValid)
     {
         db.Entry(carRequest).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.CarID = new SelectList(db.Cars, "ID", "Model", carRequest.CarID);
     return(View(carRequest));
 }
 public bool ValidateCarRequest(CarRequest request)
 {
     if (!ValidateStringParameter(request.Make) || !ValidateStringParameter(request.Model) || !ValidateStringParameter(request.DealerCode))
     {
         return(false);
     }
     if (!ValidateIntParameter(request.Year))
     {
         return(false);
     }
     return(true);
 }
Exemplo n.º 27
0
 //////////////////////////////////////////////// CAR METHODS
 public CarInfo GetCarById(CarRequest manager)
 {
     if (manager.LicenseKey != "hemligt")
     {
         throw new WebFaultException <string>(
                   "Wrong license key", HttpStatusCode.Forbidden);
     }
     else
     {
         return(carMethods.GetCarById(manager.Id));
     }
 }
Exemplo n.º 28
0
        public List <CarRequest> GetAll(loginEnt user)
        {
            var carRequest = new List <CarRequest>();
            var sql        = "select * from carRequest where username = '******'";
            var dt         = DataAccess.GetDataTable(sql);

            for (int index = 0; index < dt.Rows.Count; index++)
            {
                CarRequest h = ConvertToEntity(dt.Rows[index]);
                carRequest.Add(h);
            }
            return(carRequest);
        }
Exemplo n.º 29
0
        public void CarRequestValidation_Should_ReturnFalse_On_IncorrectInput()
        {
            //arrange
            var carRequestObject = new CarRequest()
            {
                DealerCode = "B02", Make = "  ", Model = "A4", Year = 2020
            };
            //act
            var result = _testee.ValidateCarRequest(carRequestObject);

            //assert
            result.Should().Be(false);
        }
Exemplo n.º 30
0
        public ActionResult Create([Bind(Include = "CarID, Price")] CarRequest carRequest)
        {
            carRequest.CustomerID = User.Identity.GetUserId();
            if (ModelState.IsValid)
            {
                db.CarRequests.Add(carRequest);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.CarID = new SelectList(db.Cars, "ID", "Make", carRequest.CarID);
            return(View(carRequest));
        }
 public object Get(CarRequest request)
 {
     return new CarResponse { Cars = CarsResult };
 }