Example #1
0
        public string saveUser(IList <CV_DEPARTMENT_QuaryParam> depQuaryParam)
        {
            if (depQuaryParam == null)
            {
                return("未选择联系人或应用");
            }
            string returnMessage;

            try
            {
                DateTime dtNow = SSGlobalConfig.Now;;

                IList <PM_ALT_NOTI> altNotiList = new List <PM_ALT_NOTI>();
                foreach (var item in depQuaryParam)
                {
                    PM_ALT_NOTI altNotiEntity = new PM_ALT_NOTI();
                    altNotiEntity.AlertID        = alertEntity.AlertID;
                    altNotiEntity.UserGuid       = item.userEntity.UserGuid;
                    altNotiEntity.DepartmentGuid = item.DepartmentGuid;
                    if (agentGuid != null && agentGuid != new Guid())
                    {
                        altNotiEntity.AgentGuid = agentGuid;
                    }

                    altNotiEntity.CreatedBy = item.CreatedBy;
                    altNotiEntity.CreatedOn = dtNow;
                    altNotiEntity.UpdatedBy = item.UpdatedBy;
                    altNotiEntity.UpdatedOn = item.UpdatedOn;

                    altNotiList.Add(altNotiEntity);
                }
                //先删后增
                pm_ALT_NOTIBO.SaveBatch((Guid)alertEntity.AlertID, altNotiList, out returnMessage);
                if (returnMessage == "")
                {
                    returnMessage = "联系人设置成功";
                }
                return(returnMessage);
            }
            catch (Exception ex)
            {
                returnMessage = ex.Message;
                return(returnMessage);
            }
        }
        public void Save(PM_ALT_BASE entity, IList <PM_ALT_NOTI> notis, AlertSaveOptions saveOptions,
                         out string returnMessage)
        {
            returnMessage = string.Empty;
            //
            try
            {
                DateTime?datetime = UtilDAO.GetDatabaseUtcDatetime().Value.AddHours(8);
                //
                #region check
                #region check basic
                if (saveOptions == null)
                {
                    returnMessage = "Parameter [SaveOptions saveOptions] can not be null.";
                    return;
                }
                if (entity == null)
                {
                    returnMessage = "Input parameter [ALERT entity] can not be null.";
                    return;
                }
                if (!entity.AlertID.HasValue)
                {
                    returnMessage = "Input parameter [ALERT.AlertID] can not be null.";
                    return;
                }
                if (saveOptions.IsChangeNoti)
                {
                    if (notis == null)
                    {
                        returnMessage = "Input parameter [IList<ALERT_NOTI> notis] can not be null.";
                        return;
                    }
                }
                //
                SSIdentity identity = SSAuthentication.CurrentIdentity as SSIdentity;
                if (identity == null)
                {
                    returnMessage = "[Authentication.Identity] is required.";
                    return;
                }
                #endregion
                //
                #region check alert
                if (saveOptions.IsChangeAlert)
                {
                    if (string.IsNullOrEmpty(entity.AlertName))
                    {
                        returnMessage = "[ALERT Name] is required.";
                        return;
                    }
                    if (string.IsNullOrEmpty(entity.AlertAlias))
                    {
                        returnMessage = "[ALERT Alias] is required.";
                        return;
                    }
                    if (string.IsNullOrEmpty(entity.AlertObject))
                    {
                        returnMessage = "[ALERT Object] is required.";
                        return;
                    }

                    if (!_PM_ALT_BASEDAO.CheckDatabaseObject(entity.AlertObject))
                    {
                        returnMessage = "[ALERT Object] is invalid.";
                        return;
                    }
                    //
                    if (!entity.AlertID.HasValue)
                    {
                        entity.AlertID   = Guid.NewGuid();
                        entity.CreatedBy = identity.Name;
                        entity.CreatedOn = datetime;
                    }
                    else
                    {
                        entity.ModifiedBy = identity.Name;
                        entity.ModifiedOn = datetime;
                    }
                    //
                    if (!entity.RowDeleted.HasValue)
                    {
                        entity.RowDeleted = false;
                    }
                    if (string.IsNullOrEmpty(entity.CreatedBy))
                    {
                        entity.CreatedBy = identity.Name;
                    }
                    if (!entity.CreatedOn.HasValue)
                    {
                        entity.CreatedOn = datetime;
                    }
                }
                #endregion
                //

                #region check noti
                if (saveOptions.IsChangeNoti)
                {
                }
                #endregion

                #endregion


                //
                #region save
                //
                #region save alert
                if (saveOptions.IsChangeAlert)
                {
                    PM_ALT_BASE entityExisted = this.GetEntity(entity.AlertID.Value);
                    if (entityExisted == null)
                    {
                        if (null != this.GetEntity(entity.AlertName))
                        {
                            returnMessage = "The item with the same code has existed.";
                            return;
                        }
                        //
                        entity.ModifiedBy = null;
                        entity.ModifiedOn = null;
                        //
                        this.Insert(entity);
                    }
                    else
                    {
                        this.UpdateSome(entity);
                    }
                }
                #endregion
                //

                #region save noti
                if (saveOptions.IsChangeNoti)
                {
                    _PM_ALT_NOTIBO.SaveBatch(entity.AlertID.Value, notis, out returnMessage);
                    //
                    if (!string.IsNullOrEmpty(returnMessage))
                    {
                        return;
                    }
                }
                #endregion

                #endregion
            }
            catch (Exception ex)
            {
                returnMessage = ex.Message;
                return;
            }
        }