Beispiel #1
0
 public ActionResult Edit([Bind(Include = "id,username,fullName,email,password,signupDate,lastSignin")] User user)
 {
     if (ModelState.IsValid)
     {
         db.Entry(user).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(user));
 }
Beispiel #2
0
        public ActionResult Create([Bind(Include = "id,setId,imgURL_thumb,imgURL_full")] Piece piece)
        {
            if (ModelState.IsValid)
            {
                db.Pieces.Add(piece);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.setId = new SelectList(db.Sets, "id", "name", piece.setId);
            return(View(piece));
        }
Beispiel #3
0
 public void CreateSet(int setID, List <string> pieces)
 {
     foreach (string piece in pieces)
     {
         Piece p = new Piece
         {
             setId       = setID,
             imgURL_full = piece
         };
         db.Pieces.Add(p);
     }
     db.SaveChanges();
 }
Beispiel #4
0
        public ActionResult Create([Bind(Include = "id,username,fullName,email,password,signupDate")] Admin admin)
        {
            if (ModelState.IsValid)
            {
                var dateTime = DateTime.Now;
                admin.signupDate = dateTime;

                db.Admins.Add(admin);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(admin));
        }
Beispiel #5
0
        private bool IsValid(string email, string password)
        {
            bool IsValid = false;

            using (db)
            {
                var user = db.Users.FirstOrDefault(u => u.email == email);

                if (user != null)
                {
                    if (user.password == password)
                    {
                        idfinal = user.id;

                        var dateTime = DateTime.Now;
                        user.lastSignin = dateTime;
                        db.SaveChanges();

                        IsValid = true;
                    }
                }
            }

            return(IsValid);
        }
Beispiel #6
0
        public ActionResult Create(SetViewModel set, HttpPostedFileBase[] files)
        {
            //Find logged in user
            User user   = db.Users.Single(s => s.email.Trim().ToLower() == System.Web.HttpContext.Current.User.Identity.Name.Trim().ToLower());
            int  userID = user.id;

            if (ModelState.IsValid)
            {
                SquaresEntities db     = new SquaresEntities();
                List <string>   pieces = new List <string>();

                var squareSet = new Set
                {
                    name         = set.name,
                    userId       = userID,
                    description  = set.description,
                    creationDate = DateTime.Now,
                    //likes = ,
                    //sizeData = ,
                    combinationData = "666",
                };

                //Create folders for set
                string relativePath = "/Images/" + userID + "/" + set.name;
                string path         = Server.MapPath(relativePath);
                Directory.CreateDirectory(path);

                //Lopp through pieces, save, and save path
                foreach (HttpPostedFileBase file in files)
                {
                    if (file != null)
                    {
                        string p = string.Empty;
                        p = Server.MapPath(relativePath + "/");         // make a new path to save images
                        pieces.Add(relativePath + "/" + file.FileName); // the path in database
                        file.SaveAs(p + file.FileName);
                    }
                }

                db.Sets.Add(squareSet);
                db.SaveChanges();
                int setID = squareSet.id;

                CreateSet(setID, pieces);

                return(RedirectToAction("Details", new { id = squareSet.id }));
            }
            //redirect
            return(View(set));
        }