Пример #1
0
        public ActionResult Registro([Bind(Include = "SocioID,Name,Password,Age,VideoClub")] Socio socio)
        {
            try
            {
                List <VideoClub> listaVC = new List <VideoClub>();
                VideoClub        vc      = null;
                foreach (VideoClub vd in db.VideoClubs)
                {
                    listaVC.Add(vd);
                }

                if (listaVC != null)
                {
                    string[] strCadena = Request.Form["name"].Split(',');
                    var      strnombre = strCadena[1];
                    vc = listaVC.Where(s => s.Name.Equals(strnombre)).FirstOrDefault();
                }

                if (vc != null)
                {
                    socio.VideoClub = vc;
                }
            }
            catch { }

            if (ModelState.IsValid)
            {
                db.Socios.Add(socio);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(socio));
        }
Пример #2
0
        public ActionResult Alquilar(FormCollection values)
        {
            if (values == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            try
            {
                int      id          = int.Parse(values["PeliculaID"]);
                Pelicula pelicula    = db.Peliculas.Find(id);
                Alquiler auxAlquiler = new Alquiler();
                auxAlquiler.PickUpate    = DateTime.Parse(values["Alquiler.PickUpate"]);
                auxAlquiler.DateOfReturn = DateTime.Parse(values["Alquiler.DateOfReturn"]);
                auxAlquiler.Cost         = pelicula.Price;
                pelicula.Alquiler        = auxAlquiler;
                auxAlquiler.Peliculas.Add(pelicula);
                db.Alquileres.Add(auxAlquiler);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View("Index"));
            }

            return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
        }
Пример #3
0
        public ActionResult Create([Bind(Include = "AdministradorID,Name")] Administrador administrador)
        {
            if (ModelState.IsValid)
            {
                db.Administradores.Add(administrador);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(administrador));
        }
Пример #4
0
        public ActionResult Create([Bind(Include = "VideoClubID,Name,City,Address,Zip")] VideoClub videoClub)
        {
            if (ModelState.IsValid)
            {
                db.VideoClubs.Add(videoClub);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(videoClub));
        }
Пример #5
0
        public ActionResult Create([Bind(Include = "AlquilerID,PickUpate,DateOfReturn,Cost")] Alquiler alquiler)
        {
            if (ModelState.IsValid)
            {
                db.Alquileres.Add(alquiler);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(alquiler));
        }
        private static void DeleteNewVideo(VideoClubContext videoClubContext)
        {
            var videosToRemove = videoClubContext.Videos.FirstOrDefault(item => item.Name == "AnyNameEntity");

            videoClubContext.Videos.RemoveRange(videosToRemove);
            videoClubContext.SaveChanges();
        }
 private static void AddNewVideo(VideoClubContext videoClubContext, string anyNameEntity, string anyFormatEntity)
 {
     videoClubContext.Videos.Add(new Videos {
         Name       = anyNameEntity,
         Format     = anyFormatEntity,
         CreateDate = DateTime.Now
     });
     videoClubContext.SaveChanges();
 }
Пример #8
0
        public virtual bool Add(T model, out string id)
        {
            var result = false;

            id = model.Id;
            try
            {
                _videoClubContext.Entry(model).State = EntityState.Added;
                _videoClubContext.SaveChanges();
                Helper.Log.Info($"Has been added {model.GetType().Name} successfully with ID: {model.Id}");
                result = true;
            }
            catch (Exception e)
            {
                e.CustomDescription();
            }

            return(result);
        }