public ActionResult Edit(TaxiMake taxiMake)
 {
     if (ModelState.IsValid)
     {
         tmLogic.UpdateTaxiMake(taxiMake);
         return(RedirectToAction("Index"));
     }
     return(View(taxiMake));
 }
Exemplo n.º 2
0
 public bool RemoveTaxiMake(TaxiMake taxiMake)
 {
     try
     {
         db.TaxiMakes.Remove(taxiMake);
         db.SaveChanges();
         return(true);
     }
     catch (Exception ex)
     { return(false); }
 }
Exemplo n.º 3
0
 public bool UpdateTaxiMake(TaxiMake taxiMake)
 {
     try
     {
         db.Entry(taxiMake).State = EntityState.Modified;
         db.SaveChanges();
         return(true);
     }
     catch (Exception ex)
     { return(false); }
 }
Exemplo n.º 4
0
 public bool AddTaxiMake(TaxiMake taxiMake)
 {
     try
     {
         taxiMake.MakeId = Guid.NewGuid().ToString();
         db.TaxiMakes.Add(taxiMake);
         db.SaveChanges();
         return(true);
     }
     catch (Exception ex)
     {
         return(false);
     }
 }
Exemplo n.º 5
0
        public void CreateTaxiMakes()
        {
            ApplicationDbContext db = new ApplicationDbContext();
            var taximakes           = db.TaxiMakes.ToList();

            string[] makes = { "Toyota", "Nissan", "Mercedes" };

            if (taximakes.Count() == 0)
            {
                for (int i = 0; i < makes.Length; i++)
                {
                    TaxiMake tm = new TaxiMake()
                    {
                        MakeId   = Guid.NewGuid().ToString(),
                        MakeType = makes[i]
                    };
                    db.TaxiMakes.Add(tm);
                    db.SaveChanges();
                }
            }
        }
        public ActionResult Create(TaxiMake taxiMake, HttpPostedFileBase file)
        {
            if (file != null && file.ContentLength > 0)
            {
                taxiMake.ImageType = Path.GetExtension(file.FileName);
                taxiMake.Image     = ConvertToBytes(file);
            }
            var taxiMakes = db.TaxiMakes.Where(x => x.MakeType == taxiMake.MakeType);

            if (taxiMakes.Count() != 0)
            {
                ModelState.AddModelError("", "The Route already exists");
            }

            if (ModelState.IsValid)
            {
                tmLogic.AddTaxiMake(taxiMake);
                return(RedirectToAction("Index"));
            }

            return(View());
        }