Exemplo n.º 1
0
        public DAL.User CreateUser(User user)
        {
            var checkUsername = (User)context.Users.FirstOrDefault(i => i.UserName == user.UserName);

            if (checkUsername != null)
            {
                return(null);
            }
            user.IsOnline = true;
            context.Users.Add(user);

            try
            {
                context.SaveChanges();
            }
            catch (System.Data.Entity.Validation.DbEntityValidationException dbEx)
            {
                Exception raise = dbEx;
                foreach (var validationErrors in dbEx.EntityValidationErrors)
                {
                    foreach (var validationError in validationErrors.ValidationErrors)
                    {
                        string message = string.Format("{0}:{1}",
                                                       validationErrors.Entry.Entity.ToString(),
                                                       validationError.ErrorMessage);
                        raise = new InvalidOperationException(message, raise);
                    }
                }
            }

            var newUser = (User)context.Users.FirstOrDefault(i => i.UserName == user.UserName);

            return(newUser);
        }
 public void Delete(Question entity)
 {
     {
         db.Questions.Attach(entity);
         db.Entry(entity).State = System.Data.Entity.EntityState.Deleted;
         db.SaveChanges();
     }
 }
Exemplo n.º 3
0
        public ActionResult Create(FormCollection CrearUnidad, HttpPostedFileBase Pic)
        {
            try
            {
                Unidades NewUnit = new Unidades();
                //Definiciones básicas. Nombre, Clase Inicial, Nivel, 8 estadísticas.
                NewUnit.Nombre      = CrearUnidad["Nombre"].ToString();
                NewUnit.IDClase     = int.Parse(CrearUnidad["Clase"].ToString());
                NewUnit.Nivel       = int.Parse(CrearUnidad["Nivel"].ToString());
                NewUnit.HP          = int.Parse(CrearUnidad["HP"].ToString());
                NewUnit.Fuerza      = int.Parse(CrearUnidad["Fuerza"].ToString());
                NewUnit.Magia       = int.Parse(CrearUnidad["Magia"].ToString());
                NewUnit.Habilidad   = int.Parse(CrearUnidad["Habilidad"].ToString());
                NewUnit.Velocidad   = int.Parse(CrearUnidad["Velocidad"].ToString());
                NewUnit.Suerte      = int.Parse(CrearUnidad["Suerte"].ToString());
                NewUnit.Defensa     = int.Parse(CrearUnidad["Defensa"].ToString());
                NewUnit.Resistencia = int.Parse(CrearUnidad["Resistencia"].ToString());

                //Crecimientos
                NewUnit.IDPromocion = int.Parse(CrearUnidad["Promo"].ToString());
                Boolean tempVal = CrearUnidad["Promovido"] != null ? true : false;
                TempData["Promovido"] = tempVal;
                NewUnit.Promovido     = tempVal;
                NewUnit.HPGr          = int.Parse(CrearUnidad["HPGr"].ToString());
                NewUnit.FueGr         = int.Parse(CrearUnidad["FueGr"].ToString());
                NewUnit.MagGr         = int.Parse(CrearUnidad["MagGr"].ToString());
                NewUnit.HabGr         = int.Parse(CrearUnidad["HabGr"].ToString());
                NewUnit.VelGr         = int.Parse(CrearUnidad["VelGr"].ToString());
                NewUnit.SuerGr        = int.Parse(CrearUnidad["SuerGr"].ToString());
                NewUnit.DefGr         = int.Parse(CrearUnidad["DefGr"].ToString());
                NewUnit.ResGr         = int.Parse(CrearUnidad["ResGr"].ToString());

                //Afinidad Elemental
                NewUnit.IDElemento = int.Parse(CrearUnidad["IDElemento"].ToString());

                //Foto, Fecha - Placeholders
                NewUnit.FechaNacimiento = DateTime.Parse(CrearUnidad["FechaNacimiento"].ToString());
                if (Pic != null)
                {
                    if (Path.GetExtension(Pic.FileName).ToLower() == ".jpg" || Path.GetExtension(Pic.FileName).ToLower() == ".jpeg" || Path.GetExtension(Pic.FileName).ToLower() == ".png")
                    {
                        NewUnit.Imagen = SalvarImagen(Pic);
                    }
                }
                //NewUnit.Imagen = CrearUnidad["Imagen"].ToString();

                db.Unidades.Add(NewUnit);
                db.SaveChanges();
            }
            catch (Exception)
            {
                throw;
            }
            return(RedirectToAction("Index"));
        }
Exemplo n.º 4
0
        public ActionResult Create([Bind(Include = "IDElemento,Elemento,Bonificaciones")] Elementos elementos)
        {
            if (ModelState.IsValid)
            {
                db.Elementos.Add(elementos);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(elementos));
        }
Exemplo n.º 5
0
        public ActionResult Create([Bind(Include = "IDObjeto,IDArma,Nombre,Mt,Hit,Crit,Wt,ArmaPersonal,IDClase,Imagen")] Armas armas)
        {
            if (ModelState.IsValid)
            {
                db.Armas.Add(armas);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(armas));
        }
Exemplo n.º 6
0
        public ActionResult Create([Bind(Include = "IDApoyo,IDUnitA,IDUnitB,IDElemA,IDElemB,Romance")] Apoyos apoyos)
        {
            if (ModelState.IsValid)
            {
                db.Apoyos.Add(apoyos);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.IDElemA = new SelectList(db.Elementos, "IDElemento", "Elemento", apoyos.IDElemA);
            ViewBag.IDElemB = new SelectList(db.Elementos, "IDElemento", "Elemento", apoyos.IDElemB);
            ViewBag.IDUnitA = new SelectList(db.Unidades, "IDUnit", "Nombre", apoyos.IDUnitA);
            ViewBag.IDUnitB = new SelectList(db.Unidades, "IDUnit", "Nombre", apoyos.IDUnitB);
            return(View(apoyos));
        }
Exemplo n.º 7
0
        public ActionResult Delete(int Msg_id)
        {
            int id  = Msg_id;
            Msg msg = db.Msgs.SingleOrDefault(t => t.MsgID == id);

            if (msg != null)
            {
                db.Msgs.Remove(msg);
                db.SaveChanges();
                return(RedirectToAction("index", "msg"));
            }
            else
            {
                return(RedirectToAction("index", "msg"));
            }
        }
Exemplo n.º 8
0
 public HttpResponseMessage Post([FromBody] Game gamematch)
 {
     using (GameDBEntities entities = new GameDBEntities())
     {
         entities.Games.Add(gamematch);
         entities.SaveChanges();
         return(Request.CreateResponse(HttpStatusCode.Created, new Uri(Request.RequestUri + "/" + gamematch.ID.ToString())));
     }
 }
Exemplo n.º 9
0
        public ActionResult Delete(int Msg_id)
        {
            //1.获取传递过来的msgid的值
            //Request.QueryString["Msg_id"];
            int id  = Msg_id;
            Msg msg = db.Msgs.SingleOrDefault(t => t.MsgID == Msg_id);

            if (msg != null)
            {
                db.Msgs.Remove(msg);
                db.SaveChanges();
                return(RedirectToAction("index", "msg"));
            }
            else
            {
                return(RedirectToAction("index", "msg"));
            }
        }
Exemplo n.º 10
0
        public ActionResult Create(FormCollection CrearUnidad)
        {
            try
            {
                ArbolClases NewClass = new ArbolClases();
                NewClass.Clase = CrearUnidad["Clase"].ToString();
                Boolean tempVal = CrearUnidad["Promocion"] != null ? true : false;
                TempData["Promocion"] = tempVal;
                NewClass.Promocion    = tempVal;
                NewClass.HPMax        = int.Parse(CrearUnidad["HPMax"].ToString());
                NewClass.FuerzaMax    = int.Parse(CrearUnidad["FuerzaMax"].ToString());
                NewClass.MagiaMax     = int.Parse(CrearUnidad["MagiaMax"].ToString());
                NewClass.HabMax       = int.Parse(CrearUnidad["HabMax"].ToString());
                NewClass.VelMax       = int.Parse(CrearUnidad["VelMax"].ToString());
                NewClass.SuerMax      = int.Parse(CrearUnidad["SuerMax"].ToString());
                NewClass.DefMax       = int.Parse(CrearUnidad["DefMax"].ToString());
                NewClass.ResMax       = int.Parse(CrearUnidad["ResMax"].ToString());
                db.ArbolClases.Add(NewClass);
                db.SaveChanges();
            }
            catch (DbEntityValidationException e)
            {
                foreach (var eve in e.EntityValidationErrors)
                {
                    ViewBag.MiMensaje = "Entity of type \"{0}\" in state \"{1}\" has the following validation errors:" + "-" + "-" + eve.Entry.Entity.GetType().Name + "-" + eve.Entry.State;
                    var msj = eve.Entry.Entity.GetType().Name + " " + eve.Entry.State;

                    ViewBag.MiMensaje0 = msj.ToString();

                    foreach (var ve in eve.ValidationErrors)
                    {
                        ViewBag.MiMensaje1 = "- Property: \"{0}\", Value: \"{1}\", Error: \"{2}\"" + "-" + ve.PropertyName + " " + eve.Entry.CurrentValues.GetValue <object>(ve.PropertyName) + " " + ve.ErrorMessage;
                    }
                }
                throw;
            }
            return(RedirectToAction("Index"));
        }
Exemplo n.º 11
0
 public HttpResponseMessage Delete(int id)
 {
     using (GameDBEntities entities = new GameDBEntities())
     {
         Game gamematch = entities.Games.FirstOrDefault(g => g.ID == id);
         if (gamematch != null)
         {
             entities.Games.Remove(gamematch);
             entities.SaveChanges();
             return(Request.CreateResponse(HttpStatusCode.Accepted, String.Format("Game match with ID {0} was deleted", id)));
         }
         else
         {
             return(Request.CreateResponse(HttpStatusCode.NotFound, String.Format("Game match with ID {0} not found", id)));
         }
     }
 }
Exemplo n.º 12
0
        public ActionResult Register(Account acc)
        {
            Account a = acc;

            if (acc != null)
            {
                db.Accounts.Add(acc);
                db.SaveChanges();
                TempData["msg"] = "恭喜,注册成功,请登录!";
                return(View("login"));
            }
            else
            {
                TempData["msg"] = "注册失败,重新注册!";
                return(View());
            }
        }
Exemplo n.º 13
0
 public HttpResponseMessage Put(int id, [FromBody] Game gamematch)
 {
     using (GameDBEntities entities = new GameDBEntities())
     {
         Game gameToUpdate = entities.Games.FirstOrDefault(g => g.ID == id);
         if (gameToUpdate != null)
         {
             gameToUpdate.GameType  = gamematch.GameType;
             gameToUpdate.Player1   = gamematch.Player1;
             gameToUpdate.Player2   = gamematch.Player2;
             gameToUpdate.Winner_Is = gamematch.Winner_Is;
             entities.SaveChanges();
             return(Request.CreateResponse(HttpStatusCode.Accepted, gamematch));
         }
         else
         {
             return(Request.CreateResponse(HttpStatusCode.NotFound, String.Format("Game match with ID {0} not found", id)));
         }
     }
 }
Exemplo n.º 14
0
 public void Delete(User entity)
 {
     db.Users.Attach(entity);
     db.Entry(entity).State = System.Data.Entity.EntityState.Deleted;
     db.SaveChanges();
 }