示例#1
0
 public bool addAddressToCurrentUser(Address address)
 {
     address.UserID = getCurrentUserId();
     getCurrentUser().Addresses.Add(address);
     db.SaveChanges();
     return true;
 }
示例#2
0
 public bool changeAddress(Address address)
 {
     address.UserID = getCurrentUserId();
     db.Entry(address).State = EntityState.Modified;
     db.SaveChanges();
     return true;
 }
示例#3
0
 public ActionResult EditAddress(Address address)
 {
     dso.changeAddress(address);
     return RedirectToAction("Manage");
 }
        internal Address GetAddress(ulong userId)
        {
            using (NpgsqlCommand cmd = new NpgsqlCommand())
            {
                cmd.Connection = this._connection;
                cmd.CommandText = "SELECT * FROM user_address c join address a on a.postalcode=c.postalcode and a.\"number\"=c.\"number\" and a.suffix=c.suffix where user_id= @userId";
                cmd.Parameters.AddWithValue("userId", (long)userId);

                NpgsqlDataReader reader = cmd.ExecuteReader();

                if (reader.Read())
                {
                    Address address = new Address();

                    address.PostalCode = (string)reader.GetString(reader.GetOrdinal("postalcode"));
                    address.HouseNumber = (int)reader.GetInt64(reader.GetOrdinal("number"));
                    address.Suffix = (string)reader.GetString(reader.GetOrdinal("suffix"));
                    address.Street = (string)reader.GetString(reader.GetOrdinal("street"));
                    address.City = (string)reader.GetString(reader.GetOrdinal("city"));
                    address.Type = (AddressType)Enum.ToObject(typeof(AddressType), (int)reader.GetInt32(reader.GetOrdinal("type")));
                    reader.Close();
                    return address;
                }
                reader.Close();
                return null;
            }
        }
示例#5
0
 public ActionResult AddAddress(Address address)
 {
     dso.addAddressToCurrentUser(address);
     return RedirectToAction("Manage");
 }