コード例 #1
0
        public ActionResult Cargar(MomentogAModel model)
        {
            if (!ModelState.IsValid)
            {

                IQueryable<MOMENTOGA> list = ctx.MOMENTOGA.Where(m => m.VALID == "Y").OrderByDescending(m => m.ID);
                if (list.Count() != 0 || list != null)
                {
                    ViewBag.momgalist = list.Take(3).ToList();
                }
                return View(model);
            }

            MOMENTOGA moment = ctx.MOMENTOGA.Where(m => m.USERNAME == ContextHelper.LoggedUser.USERNAME).SingleOrDefault();
            if (moment == null)
            {
                moment = new MOMENTOGA();
                moment.ID = ImageHelper.GetMomentogANextNumber();
                moment.TITULO = model.Titulo;
                moment.USERNAME = ContextHelper.LoggedUser.USERNAME;
                moment.VALID = "Y";
                moment.DESCRIPCION = null;

                MemoryStream ms = new MemoryStream();
                model.Imagen.InputStream.CopyTo(ms);
                moment.FOTO = ms.ToArray();
                ctx.MOMENTOGA.Add(moment);
                ctx.SaveChanges();

                return RedirectToAction("Galeria", "MomentogA", new { @Id = ImageHelper.GetMomentogAActualNumber() });
            }
            else
            {
                throw new ApplicationException("Solo se permite un Momento gA por usuario");
            }
        }
コード例 #2
0
        public ActionResult Galeria(string Id)
        {
            gafest2014Entities ctx = new gafest2014Entities();

            if (ContextHelper.LoggedUser.FOTO != null)
            {
                ViewBag.Foto = String.Format("data:image/gif;base64,{0}", Convert.ToBase64String(ContextHelper.LoggedUser.FOTO));
            }

            MOMENTOGA moment = new MOMENTOGA();
            if (Id == null){
                return RedirectToAction("Galeria", "MomentogA", new { @Id = ImageHelper.GetMomentogAActualNumber() });
            }
            else
            {
                int momentId = int.Parse(Id);
                moment = ctx.MOMENTOGA.SingleOrDefault<MOMENTOGA>(m => m.ID == momentId);
                ViewBag.user = moment.USER;
                ViewBag.comments = ctx.COMMENT.OrderBy(c => c.DATE).Where(c => c.MOMENTOGAID == moment.ID).ToList();
                if (moment == null || moment.VALID != "Y" || moment.FOTO == null)
                {
                    return RedirectToAction("Galeria");
                }
            }

            return View(moment);
        }