Exemplo n.º 1
0
        public ActionResult Save(Link[] links, String mapName, String LevelID, String ConceptID)
        {
            //String userName = Session["UserName"].ToString();
            String    userName = "******";
            MapOfUser mu       = new MapOfUser();

            mu.MapName   = mapName;
            mu.UserName  = userName;
            mu.LevelID   = LevelID;
            mu.ConceptID = ConceptID;
            db.MapOfUsers.Add(mu);
            db.SaveChanges();

            int mapID = db.MapOfUsers.ToList().Last().MapID;

            for (int i = 0; i < links.Length; i++)
            {
                Link li = links[i];
                li.Text = db.Links.Find(li.LinkID).Text;
                if ((li = CheckLink(li)) != null)
                {
                    LinkOfMap lm = new LinkOfMap();
                    lm.LinkID = li.LinkID;
                    lm.MapID  = mapID;
                    db.LinkOfMaps.Add(lm);
                }
            }
            db.SaveChanges();
            return(View());
        }
        public ActionResult Delete(int mapID)
        {
            var lms = from l in db.LinkOfMaps
                      where l.MapID.Equals(mapID)
                      select l;

            foreach (LinkOfMap lm in lms.ToList())
            {
                db.LinkOfMaps.Remove(lm);
            }
            db.MapOfUsers.Remove(db.MapOfUsers.Single(m => m.MapID.Equals(mapID)));
            db.SaveChanges();
            return(View());
        }
Exemplo n.º 3
0
        public ActionResult Register(User model)
        {
            if (ModelState.IsValid)
            {
                var user = db.Users.Where(k => k.UserName == model.UserName);


                if (user.Count() == 0)
                {
                    //try
                    {
                        if (ModelState.IsValid)
                        {
                            using (var db1 = new ConceptMapDBContext())
                            {
                                var crypto   = new SimpleCrypto.PBKDF2();
                                var encrPass = crypto.Compute(model.Pass);

                                var systemUser = db.Users.Create();


                                systemUser.UserName = model.UserName;
                                systemUser.Pass     = encrPass;
                                systemUser.PassSalt = crypto.Salt;

                                systemUser.FullName    = model.FullName;
                                systemUser.Email       = model.Email;
                                systemUser.PhoneNumber = model.PhoneNumber;


                                db1.Users.Add(systemUser);

                                db1.SaveChanges();
                            }

                            return(RedirectToAction("Index", "TrangChu"));
                        }
                    }
                    //catch (DbEntityValidationException dbEx)
                    //{
                    //    foreach (var validationErrors in dbEx.EntityValidationErrors)
                    //    {
                    //        foreach (var validationError in validationErrors.ValidationErrors)
                    //        {
                    //            System.Diagnostics.Trace.TraceInformation("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage);
                    //        }
                    //    }
                    //}
                }
                else
                {
                    ModelState.AddModelError("", "Tên đăng nhập này đã được sử dụng !");
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }