Beispiel #1
0
        //put request in db
        private void addRequestToDb(Request r)
        {
            List <List <string> > cycles = filterCyclesForUser(FindCycles(r.Start, r.End), r);

            foreach (List <string> cycle in cycles)
            {
                Cycle c = new Cycle()
                {
                    Start = r.Start,
                    End   = r.End
                };
                db.Cycles.Add(c);
                db.SaveChanges();
                foreach (string userId in cycle) //add usercycle for every user in cycle
                {
                    int       userIdInt = Int32.Parse(userId);
                    UserCycle uc        = new UserCycle()
                    {
                        UserId   = userIdInt,
                        User     = db.Users.Find(userIdInt),
                        CycleId  = c.CycleId,
                        Cycle    = db.Cycles.Find(c.CycleId),
                        IsLocked = false
                    };
                    db.UserCycles.Add(uc);
                }
            }
            db.Requests.Add(r);
            db.SaveChanges();
        }
Beispiel #2
0
        //[ValidateAntiForgeryToken]
        public ActionResult Create([Bind(Include = "Email,FirstName,LastName,DateOfBirth,Balance,Password,UserPicture,UserType,Country,City,Address,ApartmentPicture,ApartmentDescription,ApartmentPrice,UserId")] User user)
        {
            user.Balance  = 0;
            user.UserType = 0;
            ModelState.Remove("ApartmentScore");
            user.ApartmentScore = 1;

            foreach (User _user in db.Users)
            {
                if (_user.Email == user.Email)
                {
                    ViewBag.ErrorMessage = "email already exists";
                    return(View(user));
                }
            }

            if (ModelState.IsValid)
            {
                //upload pictures to db and change user's pic paths to server pic paths
                db.Users.Add(user);
                db.SaveChanges();

                return(RedirectToAction("../HomePage/Index"));
            }

            return(View(user));
        }
Beispiel #3
0
        public ActionResult Create([Bind(Include = "RequestId,UserId,From,To,Start,End,State")] Request request)
        {
            if (ModelState.IsValid)
            {
                db.Requests.Add(request);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.UserId = new SelectList(db.Users, "UserId", "Email", request.UserId);
            return(View(request));
        }
Beispiel #4
0
        public ActionResult Create([Bind(Include = "CycleId,Start,End")] Cycle cycle)
        {
            if (ModelState.IsValid)
            {
                db.Cycles.Add(cycle);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(cycle));
        }