Beispiel #1
0
        public ActionResult AddBuilding(int id, int row, int column, int buildingID, long buildDate, int buildTime)
        {
            city_buildings CB = new city_buildings();
            int            nextID;

            try
            {
                nextID = (entities.city_buildings.Max(u => u.id)) + 1;
            }
            catch
            {
                nextID = 0;
            }

            CB.id  = nextID;
            CB.lvl = 1;
            CB.building_positionX = row;
            CB.building_positionY = column;
            CB.building_id        = buildingID;
            CB.city_id            = id;
            CB.isPending          = 1;
            CB.buildStarted       = Constants.convertSecondsToDateTime(buildDate);
            Debug.WriteLine("U bazu idem datum:" + buildDate);
            CB.buildTime = buildTime;

            Debug.Write("ID: " + CB.id + "\n" +
                        "CityID: " + CB.city_id + "\n" +
                        "BuildingID: " + CB.building_id + "\n" +
                        "Lvl: " + CB.lvl + "\n" +
                        "X: " + CB.building_positionX + "\n" +
                        "Y: " + CB.building_positionY + "\n" +
                        "isPending: " + CB.isPending + "\n" +
                        "buildStarted: " + CB.buildStarted + "\n" +
                        "buildTime: " + CB.buildTime + "\n");

            entities.AddTocity_buildings(CB);
            entities.SaveChanges();
            return(RedirectToAction("ShowCity", "Home", new { id = id }));
        }
Beispiel #2
0
        public ActionResult Register([Bind] user RegisterData)
        {
            int maxID;

            if (!ModelState.IsValid)
            {
                return(View());
            }

            try{
                var user = (from USER in entites.users
                            where USER.username == RegisterData.username
                            select USER).First();

                return(View());
            }
            catch {
                // dopunimo RegisterData sa ID-jem koji je veci od najveceg u tabeli

                try
                {
                    maxID = (entites.users.Max(u => u.id)) + 1;
                }
                catch
                {
                    maxID = 1;
                }

                RegisterData.id = maxID;

                // ubacimo objekat u bazu

                entites.AddTousers(RegisterData);
                entites.SaveChanges();

                // nakon toga odmah i ulogujemo korisnika

                var cookie = new HttpCookie("currentUser");
                cookie.Values["id"]       = RegisterData.id.ToString();
                cookie.Values["username"] = RegisterData.username.ToString();
                cookie.Values["nickname"] = RegisterData.nickname.ToString();
                Response.AppendCookie(cookie);
                return(RedirectToAction("Index", "Home"));
            }
        }