示例#1
0
        /// <summary>
        /// Save
        /// </summary>
        public TSMSector Save()
        {
            TSMSector tsmSector = new TSMSector();

            try
            {
                if (this.ID != Guid.Empty)
                {
                    tsmSector                  = SectorService.GetSector(this.ID);
                    tsmSector.ID               = this.ID;
                    tsmSector.LastModifiedBy   = TSM.Model.TSMContext.CurrentUser.ID;
                    tsmSector.LastModifiedDate = DateTime.UtcNow;
                }
                else
                {
                    tsmSector             = new TSMSector();
                    tsmSector.CreatedBy   = TSM.Model.TSMContext.CurrentUser.ID;
                    tsmSector.CreatedDate = DateTime.UtcNow;
                }

                tsmSector.LanguageID       = TSMContext.CurrentLanguageID;
                tsmSector.Code             = this.NomenclatureCode;
                tsmSector.IsActive         = this.IsActive;
                tsmSector.IsDeleted        = false;
                tsmSector.Name             = this.SectorName;
                tsmSector.NomenclatureType = this.Nomenclaturetype;
                Guid newGuid = new Guid();
                try
                {
                    var childcode  = this.ChildCode;
                    var parentCode = this.ParentCode;
                    if (childcode != null)
                    {
                        newGuid            = Guid.Parse(childcode);
                        tsmSector.ParentID = newGuid;
                    }
                    else if (parentCode != null)
                    {
                        newGuid            = Guid.Parse(parentCode);
                        tsmSector.ParentID = newGuid;
                    }
                }
                catch { tsmSector.ParentID = null; }
                tsmSector.Type = this.Sectortype;

                SectorService.Save(tsmSector);
            }
            catch (Exception ex)
            {
                ErrorLog.WriteLog("ManageUserModel", "Save", ex, "");
            }
            return(tsmSector);
        }