Exemplo n.º 1
0
        public static bool ModifyStorage(StorageEntity StorageEntity)
        {
            long result          = 0;
            StorageRepository mr = new StorageRepository();

            if (StorageEntity != null)
            {
                StorageInfo StorageInfo = TranslateStorageInfo(StorageEntity);

                ContactJsonEntity jsonlist = null;
                if (!string.IsNullOrEmpty(StorageEntity.ContactJson))
                {
                    try
                    {
                        jsonlist = (ContactJsonEntity)JsonHelper.FromJson(StorageEntity.ContactJson, typeof(ContactJsonEntity));
                    }
                    catch (Exception ex)
                    {
                        string str = ex.ToString();
                    }
                }

                if (StorageEntity.StorageID > 0)
                {
                    StorageInfo.ChangeDate = DateTime.Now;
                    result = mr.ModifyStorage(StorageInfo);
                }
                else
                {
                    StorageInfo.CreateDate = DateTime.Now;
                    StorageInfo.ChangeDate = DateTime.Now;
                    result = mr.CreateNew(StorageInfo);
                }

                #region 更新联系人信息
                if (jsonlist != null)
                {
                    List <ContactJson> list = jsonlist.listContact;
                    if (list != null && list.Count > 0)
                    {
                        foreach (ContactJson cc in list)
                        {
                            ContactRepository cr      = new ContactRepository();
                            ContactInfo       contact = new ContactInfo();
                            contact.ContactName = cc.ContactName;
                            contact.Mobile      = cc.Mobile;
                            contact.Telephone   = cc.Telephone;
                            contact.Email       = cc.Email;
                            contact.Remark      = cc.Remark;
                            contact.UnionType   = UnionType.Storage.ToString();//仓库
                            if (cc.ContactID > 0)
                            {
                                contact.ContactID  = cc.ContactID;
                                contact.UnionID    = StorageEntity.StorageID;
                                contact.ChangeDate = DateTime.Now;
                                cr.ModifyContact(contact);
                            }
                            else
                            {
                                contact.UnionID    = StorageEntity.StorageID > 0 ? StorageEntity.StorageID : result;
                                contact.CreateDate = DateTime.Now;
                                contact.ChangeDate = DateTime.Now;
                                cr.CreateNew(contact);
                            }
                        }
                    }
                }
                #endregion
            }
            List <StorageInfo> miList = mr.GetAllstorage();
            Cache.Add("StorageALL", miList);
            return(result > 0);
        }