コード例 #1
0
ファイル: VehicleRepository.cs プロジェクト: The-mak/sgeb
        public bool Add(Vehicle vehicle)
        {
            this.context.Vehicles.AddObject(vehicle);

            if (this.context.SaveChanges() > 0)
                return true;

            return false;
        }
コード例 #2
0
ファイル: VehicleController.cs プロジェクト: The-mak/sgeb
        public ActionResult Save(Vehicle vehicle, HttpPostedFileBase[] Images)
        {
            bool jpegImages = true;

            foreach (HttpPostedFileBase image in Images)
            {
                if (image != null && !image.ContentType.Equals("image/jpeg"))
                {
                    jpegImages = false;
                    break;
                }
            }

            if (jpegImages)
            {
                if (ModelState.IsValid)
                {
                    if (Images[0] != null)
                    {
                        vehicle.Image = ConfigurationManager.AppSettings["ImagesDirectory"] + vehicle.Renavam + Path.GetExtension(Images[0].FileName);
                        Images[0].SaveAs(Server.MapPath(vehicle.Image));
                    }

                    if (Images.Length == 2 && Images[1] != null)
                    {
                        vehicle.SecondaryVehicle.Image = ConfigurationManager.AppSettings["ImagesDirectory"] + vehicle.SecondaryVehicle.Renavam + Path.GetExtension(Images[1].FileName);
                        Images[1].SaveAs(Server.MapPath(vehicle.SecondaryVehicle.Image));
                    }

                    if (vehicle.Id == 0)
                    {
                        if (this.repository.Add(vehicle))
                            return RedirectToAction("Vehicles");
                    }
                    else
                    {
                        if (this.repository.Update(vehicle))
                            return RedirectToAction("Vehicles");
                    }
                }
                else
                    TempData["ErrorMessage"] = "Existem dados incorretos";
            }
            else
                TempData["ErrorMessage"] = "Sómente imagens com a extensão JPG são aceitas";

            return View("AddEdit", vehicle);
        }
コード例 #3
0
ファイル: VehicleController.cs プロジェクト: The-mak/sgeb
        public ActionResult Add(string Type)
        {
            Vehicle vehicle = null;

            if (Type.Equals("Caminhão") || Type.Equals("Carreta"))
                vehicle = new Vehicle() { Type = Type, Owner = new Owner() { Address = new Address() } };
            else if (Type.Equals("Bi-Trem"))
                vehicle = new Vehicle()
                {
                    Type = Type,
                    Owner = new Owner() { Address = new Address() },
                    SecondaryVehicle = new Vehicle() { Type = Type, Owner = new Owner() { Address = new Address() } }
                };
            else
                return RedirectToAction("SelectType");

            return View("AddEdit", vehicle);
        }
コード例 #4
0
ファイル: SGEBModel.Designer.cs プロジェクト: The-mak/sgeb
 /// <summary>
 /// Deprecated Method for adding a new object to the Vehicles EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToVehicles(Vehicle vehicle)
 {
     base.AddObject("Vehicles", vehicle);
 }
コード例 #5
0
ファイル: SGEBModel.Designer.cs プロジェクト: The-mak/sgeb
 /// <summary>
 /// Create a new Vehicle object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="type">Initial value of the Type property.</param>
 /// <param name="plate">Initial value of the Plate property.</param>
 /// <param name="model">Initial value of the Model property.</param>
 /// <param name="chassi">Initial value of the Chassi property.</param>
 /// <param name="renavam">Initial value of the Renavam property.</param>
 /// <param name="color">Initial value of the Color property.</param>
 /// <param name="year">Initial value of the Year property.</param>
 /// <param name="city">Initial value of the City property.</param>
 /// <param name="state">Initial value of the State property.</param>
 /// <param name="aNTT">Initial value of the ANTT property.</param>
 /// <param name="image">Initial value of the Image property.</param>
 public static Vehicle CreateVehicle(global::System.Int32 id, global::System.String type, global::System.String plate, global::System.String model, global::System.String chassi, global::System.String renavam, global::System.String color, global::System.Int32 year, global::System.String city, global::System.String state, global::System.String aNTT, global::System.String image)
 {
     Vehicle vehicle = new Vehicle();
     vehicle.Id = id;
     vehicle.Type = type;
     vehicle.Plate = plate;
     vehicle.Model = model;
     vehicle.Chassi = chassi;
     vehicle.Renavam = renavam;
     vehicle.Color = color;
     vehicle.Year = year;
     vehicle.City = city;
     vehicle.State = state;
     vehicle.ANTT = aNTT;
     vehicle.Image = image;
     return vehicle;
 }
コード例 #6
0
ファイル: VehicleRepository.cs プロジェクト: The-mak/sgeb
        public bool Update(Vehicle vehicle)
        {
            var vehicleToUpdate = this.Vehicles.Where<Vehicle>(v => v.Id == vehicle.Id).SingleOrDefault<Vehicle>();

            vehicleToUpdate.Plate = vehicle.Plate;
            vehicleToUpdate.Model = vehicle.Model;
            vehicleToUpdate.Chassi = vehicle.Chassi;
            vehicleToUpdate.Renavam = vehicle.Renavam;
            vehicleToUpdate.Color = vehicle.Color;
            vehicleToUpdate.Year = vehicle.Year;
            vehicleToUpdate.City = vehicle.City;
            vehicleToUpdate.State = vehicle.State;
            vehicleToUpdate.ANTT = vehicle.ANTT;

            if(!String.IsNullOrWhiteSpace(vehicle.Image))
                vehicleToUpdate.Image = vehicle.Image;

            vehicleToUpdate.Owner.Name = vehicle.Owner.Name;
            vehicleToUpdate.Owner.DocNumber = vehicle.Owner.DocNumber;
            vehicleToUpdate.Owner.Address.Street = vehicle.Owner.Address.Street;
            vehicleToUpdate.Owner.Address.Number = vehicle.Owner.Address.Number;
            vehicleToUpdate.Owner.Address.Neighborhood = vehicle.Owner.Address.Neighborhood;
            vehicleToUpdate.Owner.Address.ZipCode = vehicle.Owner.Address.ZipCode;
            vehicleToUpdate.Owner.Address.City = vehicle.Owner.Address.City;
            vehicleToUpdate.Owner.Address.State = vehicle.Owner.Address.State;
            vehicleToUpdate.Owner.Phone = vehicle.Owner.Phone;

            if (vehicle.Type.Equals("Bi-Trem"))
            {
                vehicleToUpdate.SecondaryVehicle.Plate = vehicle.SecondaryVehicle.Plate;
                vehicleToUpdate.SecondaryVehicle.Model = vehicle.SecondaryVehicle.Model;
                vehicleToUpdate.SecondaryVehicle.Chassi = vehicle.SecondaryVehicle.Chassi;
                vehicleToUpdate.SecondaryVehicle.Renavam = vehicle.SecondaryVehicle.Renavam;
                vehicleToUpdate.SecondaryVehicle.Color = vehicle.SecondaryVehicle.Color;
                vehicleToUpdate.SecondaryVehicle.Year = vehicle.SecondaryVehicle.Year;
                vehicleToUpdate.SecondaryVehicle.City = vehicle.SecondaryVehicle.City;
                vehicleToUpdate.SecondaryVehicle.State = vehicle.SecondaryVehicle.State;
                vehicleToUpdate.SecondaryVehicle.ANTT = vehicle.SecondaryVehicle.ANTT;

                if (!String.IsNullOrEmpty(vehicle.SecondaryVehicle.Image) && !String.IsNullOrWhiteSpace(vehicle.SecondaryVehicle.Image))
                    vehicleToUpdate.SecondaryVehicle.Image = vehicle.SecondaryVehicle.Image;

                vehicleToUpdate.SecondaryVehicle.Owner.Name = vehicle.SecondaryVehicle.Owner.Name;
                vehicleToUpdate.SecondaryVehicle.Owner.DocNumber = vehicle.SecondaryVehicle.Owner.DocNumber;
                vehicleToUpdate.SecondaryVehicle.Owner.Address.Street = vehicle.SecondaryVehicle.Owner.Address.Street;
                vehicleToUpdate.SecondaryVehicle.Owner.Address.Number = vehicle.SecondaryVehicle.Owner.Address.Number;
                vehicleToUpdate.SecondaryVehicle.Owner.Address.Neighborhood = vehicle.SecondaryVehicle.Owner.Address.Neighborhood;
                vehicleToUpdate.SecondaryVehicle.Owner.Address.ZipCode = vehicle.SecondaryVehicle.Owner.Address.ZipCode;
                vehicleToUpdate.SecondaryVehicle.Owner.Address.City = vehicle.SecondaryVehicle.Owner.Address.City;
                vehicleToUpdate.SecondaryVehicle.Owner.Address.State = vehicle.SecondaryVehicle.Owner.Address.State;
                vehicleToUpdate.SecondaryVehicle.Owner.Phone = vehicle.SecondaryVehicle.Owner.Phone;
            }

            if (this.context.SaveChanges() > 0)
                return true;
            else
                return false;
        }