Example #1
0
        public bool Add(Driver driver)
        {
            this.context.Drivers.AddObject(driver);

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

            return false;
        }
Example #2
0
        public bool Update(Driver driver)
        {
            var driverToUpdate = (from d in this.Drivers where d.Id == driver.Id select d).SingleOrDefault<Driver>();

            driverToUpdate.Rg.Name = driver.Rg.Name;
            driverToUpdate.Rg.Number = driver.Rg.Number;
            driverToUpdate.Rg.BornDate = driver.Rg.BornDate;
            driverToUpdate.Rg.EmittedDate = driver.Rg.EmittedDate;
            driverToUpdate.Rg.FathersName = driver.Rg.FathersName;
            driverToUpdate.Rg.MothersName = driver.Rg.MothersName;
            driverToUpdate.Rg.City = driver.Rg.City;
            driverToUpdate.Rg.State = driver.Rg.State;
            if(!String.IsNullOrEmpty(driver.Rg.Image) && !String.IsNullOrWhiteSpace(driver.Rg.Image))
                driverToUpdate.Rg.Image = driver.Rg.Image;

            driverToUpdate.Cpf.Number = driver.Cpf.Number;
            if(!String.IsNullOrEmpty(driver.Cpf.Image) && !String.IsNullOrWhiteSpace(driver.Cpf.Image))
                driverToUpdate.Cpf.Image = driver.Cpf.Image;

            driverToUpdate.Cnh.Number = driver.Cnh.Number;
            driverToUpdate.Cnh.Category = driver.Cnh.Category;
            driverToUpdate.Cnh.Record = driver.Cnh.Record;
            driverToUpdate.Cnh.EmittedDate = driver.Cnh.EmittedDate;
            driverToUpdate.Cnh.DueDate = driver.Cnh.DueDate;
            if(!String.IsNullOrEmpty(driver.Cnh.Image) && !String.IsNullOrWhiteSpace(driver.Cnh.Image))
                driverToUpdate.Cnh.Image = driver.Cnh.Image;

            driverToUpdate.Address.Street = driver.Address.Street;
            driverToUpdate.Address.Number = driver.Address.Number;
            driverToUpdate.Address.Neighborhood = driver.Address.Neighborhood;
            driverToUpdate.Address.ZipCode = driver.Address.ZipCode;
            driverToUpdate.Address.City = driver.Address.City;
            driverToUpdate.Address.State = driver.Address.State;

            driverToUpdate.Contact.HomePhone = driver.Contact.HomePhone;
            driverToUpdate.Contact.CelPhone = driver.Contact.CelPhone;
            driverToUpdate.Contact.RefPhone1 = driver.Contact.RefPhone1;
            driverToUpdate.Contact.RefContact1 = driver.Contact.RefContact1;
            driverToUpdate.Contact.RefPhone2 = driver.Contact.RefPhone2;
            driverToUpdate.Contact.RefContact2 = driver.Contact.RefContact2;

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

            return false;
        }
Example #3
0
        public ActionResult Save(Driver driver, 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)
                    {
                        driver.Rg.Image = ConfigurationManager.AppSettings["ImagesDirectory"] + driver.Rg.Number + Path.GetExtension(Images[0].FileName);
                        Images[0].SaveAs(Server.MapPath(driver.Rg.Image));
                    }

                    if (Images[1] != null)
                    {
                        driver.Cpf.Image = ConfigurationManager.AppSettings["ImagesDirectory"] + driver.Cpf.Number + Path.GetExtension(Images[1].FileName);
                        Images[1].SaveAs(Server.MapPath(driver.Cpf.Image));
                    }

                    if (Images[2] != null)
                    {
                        driver.Cnh.Image = ConfigurationManager.AppSettings["ImagesDirectory"] + driver.Cnh.Number + Path.GetExtension(Images[2].FileName);
                        Images[2].SaveAs(Server.MapPath(driver.Cnh.Image));
                    }

                    if (driver.Id == 0)
                    {
                        if (this.repository.Add(driver))
                            return RedirectToAction("Drivers");
                    }
                    else if (driver.Id != 0)
                    {
                        if (this.repository.Update(driver))
                            return RedirectToAction("Drivers");
                    }
                }
                else
                    TempData["ErrorMessage"] = "Existem dados incorretos";
            }
            else
                TempData["ErrorMessage"] = "Somente arquivos com a extensão .JPG são aceitos";

            return View("AddEdit", driver);
        }
Example #4
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Drivers EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToDrivers(Driver driver)
 {
     base.AddObject("Drivers", driver);
 }
Example #5
0
 /// <summary>
 /// Create a new Driver object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 public static Driver CreateDriver(global::System.Int32 id)
 {
     Driver driver = new Driver();
     driver.Id = id;
     return driver;
 }