public ActionResult Create(AddLivingSpaceview collection)
 {
     TempData["err"] = "";
     try
     {
         AddNewLivingSpace(collection);
         return(RedirectToAction("Index"));
     }
     catch (Exception death)
     {
         TempData["err"] = death.Message;
         return(RedirectToAction("Index"));
     }
 }
        public bool AddNewLivingSpace(AddLivingSpaceview LivingSpaceView)
        {
            string          connStr         = ConfigurationManager.ConnectionStrings["MysqlConnection"].ConnectionString;
            MySqlConnection mySqlConnection = new MySqlConnection(connStr);
            string          sqlQuery        = "INSERT INTO livingspace (`adress`, `roomNumber`, `maxCapacity`) VALUES (?adress, ?roomnumber, ?maxcapacity)";
            MySqlCommand    mySqlCommand    = new MySqlCommand(sqlQuery, mySqlConnection);

            mySqlCommand.Parameters.Add("?adress", MySqlDbType.VarChar).Value    = LivingSpaceView.adress;
            mySqlCommand.Parameters.Add("?roomnumber", MySqlDbType.Int32).Value  = LivingSpaceView.roomNumber;
            mySqlCommand.Parameters.Add("?maxcapacity", MySqlDbType.Int32).Value = LivingSpaceView.maxCapacity;
            mySqlConnection.Open();
            mySqlCommand.ExecuteNonQuery();
            mySqlConnection.Close();
            return(true);
        }
        public void AddNewLivingSpace(AddLivingSpaceview collection)
        {
            int numberOfLivingSpaces = collection.roomNumber;
            List <LivingSpaceListView> LivingSpaceList = LivingSpaceRepos.GetLivingSpaces();

            foreach (var LS in LivingSpaceList)
            {
                if (collection.adress == LS.adress)
                {
                    TempData["err"] = "Address already exists.";
                }
            }

            if (numberOfLivingSpaces == 1)
            {
                if (collection.adress == null || collection.roomNumber == 0 || collection.maxCapacity == 0)
                {
                    TempData["err"] = "Missing data.";
                    return;
                }
                LivingSpaceRepos.AddNewLivingSpace(collection);
            }
            else
            {
                for (int i = 1; i <= numberOfLivingSpaces; i++)
                {
                    if (collection.adress == null || collection.roomNumber == 0 || collection.maxCapacity == 0)
                    {
                        TempData["err"] = "Missing data.";
                        return;
                    }
                    collection.roomNumber = i;
                    LivingSpaceRepos.AddNewLivingSpace(collection);
                }
            }
        }
        public ActionResult Create()
        {
            AddLivingSpaceview LivingSpaceView = new AddLivingSpaceview();

            return(View(LivingSpaceView));
        }