Beispiel #1
0
        public static string ToXml(this VehicleRegistration input, bool excludeOuter = false)
        {
            if (input == null && excludeOuter)
            {
                return("<VehicleRegistration />");
            }
            var builder = new StringBuilder();

            if (!excludeOuter)
            {
                builder.Append("<VehicleRegistration>");
            }
            builder.AddXml("maker", input.vehicle.maker)
            .AddXml("model", input.vehicle.model)
            .AddXml("licensePlate", input.licencePlate)
            .AddXml("licenseNumber", input.licenceNumber);
            if (excludeOuter)
            {
                builder.Append("\n");
            }
            else
            {
                builder.Append("\n</VehicleRegistration>");
            }
            return(builder.ToString());
        }
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Manufacturer,Year,Weight")] VehicleRegistration vehicleRegistration)
        {
            if (id != vehicleRegistration.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(vehicleRegistration);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!VehicleRegistrationExists(vehicleRegistration.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(vehicleRegistration));
        }
Beispiel #3
0
        public async Task <IActionResult> PutVehicleRegistration(int id, VehicleRegistration vehicleRegistration)
        {
            if (id != vehicleRegistration.RegistrationId)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
        public ActionResult Create()
        {
            try
            {
                var id             = Request.Form["OwnerID"];
                var email          = Request.Form["EmailAddress"];
                var vehicle        = Request.Form["Vehicle"];
                var dateRegistered = Request.Form["DateOfRegistration"];

                VehicleRegistration registration = new VehicleRegistration()
                {
                    OwnerID            = id,
                    EmailAddress       = email,
                    Vehicle            = vehicle,
                    DateOfRegistration = DateTime.Parse(dateRegistered)
                };

                // TODO: Save the vehicle registration in a database

                ViewBag.Message   = "Vehicle was registered successfully.";
                ViewBag.Submitted = true;
            }
            catch
            {
                ViewBag.Message   = "There was an error while registering the vehicle.";
                ViewBag.Submitted = false;
            }
            return(View());
        }
        public APIGatewayProxyResponse FunctionHandler(APIGatewayProxyRequest request, ILambdaContext context)
        {
            VehicleRegistration vehicleRegistration = JsonConvert.DeserializeObject <VehicleRegistration>(request.Body);

            return(this.qldbDriver.Execute(transactionExecutor =>
            {
                context.Logger.Log($"Checking vehicle registration already exists for VIN {vehicleRegistration.Vin}.");
                if (!CheckIfVinAlreadyExists(transactionExecutor, vehicleRegistration.Vin))
                {
                    context.Logger.Log($"Vehicle registration does not exist for VIN {vehicleRegistration.Vin}, returning not found.");
                    return new APIGatewayProxyResponse
                    {
                        StatusCode = (int)HttpStatusCode.NotFound
                    };
                }

                context.Logger.Log($"Vehicle registration already exists, checking what's changed between current value and request.");

                IEnumerable <string> existingSecondaryOwners = GetSecondaryOwners(transactionExecutor, vehicleRegistration.Vin);
                IEnumerable <string> newSecondaryOwnersGovIds = vehicleRegistration.Owners.SecondaryOwners
                                                                .Select(x => x.PersonId)
                                                                .Except(existingSecondaryOwners);
                if (!newSecondaryOwnersGovIds.Any())
                {
                    context.Logger.Log($"Nothing changed, returning not modified.");
                    return new APIGatewayProxyResponse
                    {
                        StatusCode = (int)HttpStatusCode.NotModified
                    };
                }

                string secondaryOwnerPersonDocumentId = this.tableMetadataService.GetDocumentId(transactionExecutor, PersonTableName, "GovId", newSecondaryOwnersGovIds.First());
                if (!CheckIfSecondaryOwnerExists(existingSecondaryOwners, secondaryOwnerPersonDocumentId))
                {
                    context.Logger.Log($"Secondary owner does not exists with document ID {secondaryOwnerPersonDocumentId}, adding secondary owner.");
                    IIonValue ionVin = this.valueFactory.NewString(vehicleRegistration.Vin);
                    IIonValue ionSecondaryOwner = ConvertOwnerToIonValue(new Owner {
                        PersonId = secondaryOwnerPersonDocumentId
                    });

                    IResult result = transactionExecutor.Execute($"FROM VehicleRegistration AS v WHERE v.VIN = ? " +
                                                                 "INSERT INTO v.Owners.SecondaryOwners VALUE ?", ionVin, ionSecondaryOwner);

                    context.Logger.Log($"Secondary owner added with document ID {secondaryOwnerPersonDocumentId}, returning OK.");
                    return new APIGatewayProxyResponse
                    {
                        StatusCode = (int)HttpStatusCode.OK
                    };
                }
                else
                {
                    context.Logger.Log($"Secondary owner already exists, returning not modified.");
                    return new APIGatewayProxyResponse
                    {
                        StatusCode = (int)HttpStatusCode.NotModified
                    };
                }
            }));
        }
Beispiel #6
0
        public void RaiseEvent()
        {
            VehicleRegistration selectedVehicle = null;

            selectedVehicle = dgvVehicles.SelectedCells.Count > 0 ? _selectedCustomer.VehicleRegistrations.First(x => x.RegisteredVehicle.RegistrationNumber == dgvVehicles[0, dgvVehicles.SelectedCells[0].RowIndex].Value.ToString()) : _selectedCustomer.VehicleRegistrations.First(x => x.RegisteredVehicle.RegistrationNumber == dgvVehicles[0, 0].Value.ToString());

            OnCustomerSelection(new FormSelectionArgs <Customer>(selectedVehicle.RegisteredTo));
            OnVehicleSelection(new FormSelectionArgs <VehicleRegistration>(selectedVehicle));
        }
Beispiel #7
0
 public Vehicle()
 {
     Specification  = new VehicleSpecification();
     Seller         = new VehicleSeller();
     ComplianceDate = new SimpleDate();
     BuildDate      = new SimpleDate();
     Warranty       = new VehicleWarranty();
     Identification = new List <TypeValue>();
     Registration   = new VehicleRegistration();
 }
        public async Task <IActionResult> Create([Bind("Id,Name,Manufacturer,Year,Weight")] VehicleRegistration vehicleRegistration)
        {
            if (ModelState.IsValid)
            {
                _context.Add(vehicleRegistration);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(vehicleRegistration));
        }
        public APIGatewayProxyResponse FunctionHandler(APIGatewayProxyRequest request, ILambdaContext context)
        {
            VehicleRegistration vehicleRegistration = JsonConvert.DeserializeObject <VehicleRegistration>(request.Body);

            return(this.qldbDriver.Execute(transactionExecutor =>
            {
                context.Logger.Log($"Looking for person document ID {vehicleRegistration.Owners?.PrimaryOwner?.PersonId}.");
                string primaryOwnerPersonDocumentId = this.tableMetadataService.GetDocumentId(transactionExecutor, PersonTableName, "GovId", vehicleRegistration.Owners?.PrimaryOwner?.PersonId);

                if (string.IsNullOrWhiteSpace(primaryOwnerPersonDocumentId))
                {
                    context.Logger.Log($"No person found with GovId {vehicleRegistration.Owners?.PrimaryOwner?.PersonId}, returning not found.");
                    return new APIGatewayProxyResponse
                    {
                        StatusCode = (int)HttpStatusCode.NotFound
                    };
                }

                context.Logger.Log($"Checking vehicle registration already exists for VIN {vehicleRegistration.Vin}.");
                if (CheckIfVinAlreadyExists(transactionExecutor, vehicleRegistration.Vin))
                {
                    context.Logger.Log($"Vehicle registration does exist for VIN {vehicleRegistration.Vin}, returning not modified.");
                    return new APIGatewayProxyResponse
                    {
                        StatusCode = (int)HttpStatusCode.NotModified
                    };
                }

                context.Logger.Log($"Inserting vehicle registration for VIN {vehicleRegistration.Vin}.");
                vehicleRegistration.Owners.PrimaryOwner.PersonId = primaryOwnerPersonDocumentId;
                IIonValue ionVehicleRegistration = ConvertObjectToIonValue(vehicleRegistration);

                transactionExecutor.Execute($"INSERT INTO VehicleRegistration ?", ionVehicleRegistration);

                context.Logger.Log($"Inserted vehicle registration for VIN {vehicleRegistration.Vin}, returning OK.");
                return new APIGatewayProxyResponse
                {
                    StatusCode = (int)HttpStatusCode.OK
                };
            }));
        }
Beispiel #10
0
        /// <summary>
        /// Insert/Update of Vehicle Registration
        /// </summary>
        /// <param name="objReg"></param>
        /// <returns></returns>
        public int VehicleRegistrationInsertUpdate(VehicleRegistration objReg)
        {
            int i = 0;

            try
            {
                using (SqlConnection con = new SqlConnection(connectionString))
                {
                    con.Open();
                    SqlCommand cmd = con.CreateCommand();
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.CommandText = "usp_VehicleRegistrationInsertUpdate";
                    cmd.Parameters.AddWithValue("@RegId", objReg.RegId);
                    cmd.Parameters.AddWithValue("@VehicleID", objReg.VehicleID);
                    cmd.Parameters.AddWithValue("@RegNo", objReg.RegNo);
                    cmd.Parameters.AddWithValue("@RegCountryID", objReg.RegCountryID);
                    cmd.Parameters.AddWithValue("@RegStateID", objReg.RegStateID);
                    cmd.Parameters.AddWithValue("@RegDate", objReg.RegDate);
                    cmd.Parameters.AddWithValue("@RegExpiry", objReg.RegExpiry);
                    cmd.Parameters.AddWithValue("@RegCost", objReg.RegCost);
                    cmd.Parameters.AddWithValue("@RegPlateCodeID", objReg.RegPlateCodeID);
                    cmd.Parameters.AddWithValue("@RegPlateColorID", objReg.RegPlateColorID);
                    cmd.Parameters.AddWithValue("@UserID", objReg.UserId);
                    cmd.Parameters.AddWithValue("@IsActive", objReg.IsActive);

                    //SqlParameter output = new SqlParameter("@Return_Value", SqlDbType.Int);
                    //output.Direction = ParameterDirection.ReturnValue;
                    //cmd.Parameters.Add(output);
                    cmd.ExecuteNonQuery();
                    i = 1;
                }
            }
            catch (Exception ex)
            {
                i = 0;
                throw ex;
            }
            return(i);
        }
Beispiel #11
0
        public static string TestObjectSerializer(ScreenManager screenMan, out int errorsAdded)
        {
            int           num         = 0;
            string        str         = "";
            List <string> stringList1 = new List <string>();
            List <string> stringList2 = (List <string>)ObjectSerializer.DeserializeObject(Utils.GenerateStreamFromString(ObjectSerializer.SerializeObject((object)stringList1)), stringList1.GetType());

            if (stringList2 == null || stringList2.Count != 0)
            {
                ++num;
                str += "\nError deserializing empty list";
            }
            stringList1.Add("test 1");
            stringList1.Add("12345");
            List <string> stringList3 = (List <string>)ObjectSerializer.DeepCopy((object)stringList1);

            if (stringList3.Count != 2 || stringList3[0] != "test 1" || stringList3[1] != "12345")
            {
                ++num;
                str += "\nError deserializing empty list";
            }
            VehicleRegistration self = new VehicleRegistration()
            {
                licenceNumber = "1123-123", licencePlate = "11-11", vehicle = new VehicleType()
                {
                    maker = "asdf", model = "another asdf"
                }
            };
            VehicleRegistration to = (VehicleRegistration)ObjectSerializer.DeepCopy((object)self);

            if (!Utils.PublicInstancePropertiesEqual <VehicleRegistration>(self, to))
            {
                ++num;
                str += "\nError auto deserializing vehicle info\n";
            }
            errorsAdded = num;
            return(str);
        }
Beispiel #12
0
 /// <summary>
 /// Insert/Update of Vehicle Registration
 /// </summary>
 /// <param name="objReg"></param>
 /// <returns></returns>
 public int VehicleRegistrationInsertUpdate(VehicleRegistration objReg)
 {
     return(objDal.VehicleRegistrationInsertUpdate(objReg));
 }
Beispiel #13
0
        public async Task <ActionResult <VehicleRegistration> > PostVehicleRegistration(VehicleRegistration vehicleRegistration)
        {
            _context.VehicleRegistration.Add(vehicleRegistration);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetVehicleRegistration", new { id = vehicleRegistration.RegistrationId }, vehicleRegistration));
        }