//CREATE NEW MARCAS ELEMENT
 private Marcas newMarca(MarcasView marcasView)
 {
     return(new Marcas {
         IdMarca = marcasView.IdMarca,
         Marca = marcasView.Marca,
         Descripcion = marcasView.Descripcion,
         Alta = marcasView.Alta,
         ActInac = marcasView.ActInac,
         Imagen = marcasView.Imagen,
         TipoMarca = marcasView.TipoMarca,
     });
 }
        public ActionResult Create(MarcasView view)
        {
            if (view == null)
            {
                ViewBag.DropDownTipos = (from c in db.Tipos select new { c.IdTipos, c.NombreTipo }).Distinct();
                ViewBag.ResultMessage = "COMPLETA LOS CAMPOS POR FAVOR!!";
                return(View(view));
            }

            view.Alta = DateTime.Now;


            if (!ModelState.IsValid)
            {
                ViewBag.DropDownTipos = (from c in db.Tipos select new { c.IdTipos, c.NombreTipo }).Distinct();
                ViewBag.ResultMessage = "ALGUN CAMPO NO ES ADMITIDO REVISA POR FAVOR";
                return(View(view));
            }


            using (var transaction = db.Database.BeginTransaction())
            {
                try
                {
                    view.Imagen = "NULL";

                    var pic    = string.Empty;
                    var folder = "~/Images/Brands";
                    if (view.ImageFile != null)
                    {
                        pic = FileHelper.UploadPhoto(view.ImageFile, folder);
                        pic = string.Format("{0}/{1}", folder, pic);
                    }
                    var Marcas = newMarca(view);
                    Marcas.Imagen = pic;
                    db.Marcas.Add(Marcas);
                    db.SaveChanges();


                    transaction.Commit();


                    ViewBag.ResultMessage = "1";
                    ViewBag.DropDownTipos = (from c in db.Tipos select new { c.IdTipos, c.NombreTipo }).Distinct();
                    view = null;
                    return(View());//POR SI DESEA AGREGAR MAS
                    //return RedirectToAction("Index");
                }
                catch (Exception)
                {
                    transaction.Rollback();
                    ViewBag.ResultMessage = "0";
                }
            }

            ViewBag.ResultMessage = "1";
            ViewBag.DropDownTipos = (from c in db.Tipos select new { c.IdTipos, c.NombreTipo }).Distinct();
            return(View());

            #region MyRegion

            //if (ModelState.IsValid)
            //{


            //    var pic = string.Empty;
            //    var folder = "~/Images/Brands";
            //    if (view.ImageFile != null)
            //    {
            //        pic = FileHelper.UploadPhoto(view.ImageFile, folder);
            //        pic = string.Format("{0}/{1}", folder, pic);
            //    }
            //    var Marcas = newMarca(view);
            //    Marcas.Imagen = pic;
            //    db.marcas.Add(Marcas);
            //    db.SaveChanges();
            //    return RedirectToAction("Index");
            //}

            //return View(view);
            #endregion
        }