示例#1
0
        public Result <long> Update(TCom.EF.MyAddr data)
        {
            Result <long> result = new Result <long>();

            try
            {
                using (TN db = new TN())
                {
                    if (data.idaddr <= 0)
                    {
                        data.idaddr = Pub.ID();
                        db.MyAddrs.Add(data);
                    }
                    else
                    {
                        DbEntityEntry <TCom.EF.MyAddr> entry = db.Entry <TCom.EF.MyAddr>(data);
                        if (data.inuse == false)
                        {
                            entry.State = EntityState.Deleted;
                        }
                        else
                        {
                            entry.State = EntityState.Unchanged;
                            entry.Property("contact").IsModified  = true;
                            entry.Property("phone").IsModified    = true;
                            entry.Property("province").IsModified = true;
                            entry.Property("city").IsModified     = true;
                            entry.Property("district").IsModified = true;
                            entry.Property("street").IsModified   = true;
                            entry.Property("tag").IsModified      = true;
                            entry.Property("isdv").IsModified     = true;
                            entry.Property("notes").IsModified    = true;
                            entry.Property("inuse").IsModified    = true;
                        }
                    }
                    if (db.SaveChanges() > 0)
                    {
                        result.Data = data.idaddr;
                    }
                    result.Code = R.Ok;
                }
            }
            catch (Exception)
            {
                result.Code = R.Error;
                result.Msg  = "出现异常";
            }
            return(result);
        }