Пример #1
0
        protected override void OnInit(EventArgs e)
        {
            LogDebug("GeneralPage OnInit");
            this.BaseHelperObj      = new ETEMModel.Helpers.BaseHelper();
            this.AdminClientRef     = new Administration();
            this.CommonClientRef    = new Common();
            this.EmployeClientRef   = new EmployeRef();
            this.CostCalculationRef = new ETEMModel.Services.CostCalculation.CostCalculationRef();

            this.CallContext = new CallContext();

            this.FormContext = new FormContext();
            this.FormContext.RequestMeasure = new RequestMeasure(this.Page.GetType().FullName);

            this.FormContext.UserProps = this.UserProps;

            this.FormContext.DictionaryKeyValue = DictionaryKeyValue;
            this.FormContext.DictionaryKeyType  = DictionaryKeyType;
            this.FormContext.DictionarySetting  = DictionarySetting;

            AdminClientRef.DictionaryKeyType  = DictionaryKeyType;
            AdminClientRef.DictionaryKeyValue = DictionaryKeyValue;


            this.FormContext.DictionaryPermittedActionSetting = DictionaryPermittedActionSetting;

            //Функционалност за разкрептиране на криптираните ключове в QueryString_а
            if (Request.QueryString.Count > 0)
            {
                string rawQueryString = System.Web.HttpUtility.UrlDecode(Request.RawUrl.Substring(Request.RawUrl.IndexOf('?') + 1));

                string queryString = "";

                if (rawQueryString.IndexOf("Cript=false") == -1)
                {
                    queryString = ETEMModel.Helpers.BaseHelper.Decrypt(rawQueryString);
                }
                else
                {
                    queryString = rawQueryString;
                }

                string val;
                string key;

                string[] keys_values = queryString.Split('&');

                foreach (string key_value in keys_values)
                {
                    string[] kv = key_value.Split('=');

                    key = kv[0];
                    val = kv[1];

                    this.FormContext.QueryString.Add(key, val);
                }
            }

            if (userProps != null)
            {
                userProps.LastRequestDateTime = DateTime.Now;
                userProps.Page = this.Page.GetType().FullName;
            }



            base.OnInit(e);
        }
Пример #2
0
        /// <summary>
        /// Saves list of Entities
        /// </summary>
        /// <typeparam name="E"></typeparam>
        /// <param name="entities"></param>
        /// <param name="inputContext"></param>
        /// <param name="setNull"> this param is flag for refrection save, and it allows to set null or string empry as value of some prop</param>
        /// <param name="propertiesToChange">if this is != null, it means that only selected protoperties of the Entity will be saved</param>
        /// <returns></returns>

        public virtual CallContext EntitySave <E>(List <T> entities, CallContext inputContext, List <string> propertiesToChange = null, bool?allowNullAsPropvalue = null) where E : Identifiable
        {
            CallContext outputContext = new CallContext();

            outputContext.CurrentConsumerID = inputContext.CurrentConsumerID;

            try
            {
                SetCallContextDataFromSession(outputContext);

                //outputContext.CurrentConsumerNames = props.PersonTwoNamePlusTitle;
                //outputContext.CurrentConsumerSessionId = props.SessionID;
                //outputContext.CurrentConsumerID = props.IdUser;
                //
            }
            catch (Exception ex)
            {
                outputContext.CurrentConsumerID = inputContext.CurrentConsumerID;
                BaseHelper.Log("Грешка създаване на обекта сесия в модела на приложението!");
                BaseHelper.Log(ex.Message);
            }



            outputContext.PersonType       = inputContext.PersonType;
            outputContext.ResultCode       = ETEMEnums.ResultEnum.Success;
            outputContext.securitySettings = inputContext.securitySettings;
            outputContext.CurrentYear      = inputContext.CurrentYear;
            outputContext.CurrentPeriod    = inputContext.CurrentPeriod;


            List <Tuple <EventLog, T> > itemsToLog = new List <Tuple <EventLog, T> >();

            for (int i = 0; i < entities.Count; i++)
            {
                var entity = entities[i];
                if (!HasUserActionPermission(entity, outputContext, inputContext))
                {
                    return(outputContext);
                }

                if (entity.ValidateEntity(outputContext).Count > 0)
                {
                    return(outputContext);
                }

                if (entity != null && entity.EntityID != Constants.INVALID_ID_ZERO && entity.EntityID != Constants.INVALID_ID)
                {
                    savedEntity = GetEntityById(entity.EntityID);

                    if (savedEntity != null)
                    {
                        outputContext.ActionName = Constants.ACTION_UPDATE;
                        if (propertiesToChange == null)
                        {
                            EntityToEntity(entity, savedEntity);
                        }
                        else
                        {
                            BaseGenericHelper <T> .EntityToEntityByReflection(entity, savedEntity, propertiesToChange, allowNullAsPropvalue);
                        }

                        if (savedEntity is IModifiable)
                        {
                            ((IModifiable)savedEntity).SetModificationData(outputContext);
                        }

                        outputContext.EntityID = savedEntity.EntityID.ToString();

                        outputContext.Message    = BaseHelper.GetCaptionString("Entity_is_not_update");
                        outputContext.ResultCode = ETEMEnums.ResultEnum.Error;

                        try
                        {
                            dbContext.SaveChanges();
                        }
                        catch (Exception ex)
                        {
                            BaseHelper.Log("Грешка в BaseClassBL.EntitySave() - Update");
                            BaseHelper.Log(ex.Message);
                            BaseHelper.Log(ex.StackTrace);
                        }

                        outputContext.listKvEntityID.Add(new KeyValuePair <string, int>(EntitySetName, entity.EntityID));
                        outputContext.Message    = BaseHelper.GetCaptionString("Entity_is_update_successful");
                        outputContext.ResultCode = ETEMEnums.ResultEnum.Success;

                        EventLog simpleLog = MakeEventLog(outputContext, savedEntity);
                        itemsToLog.Add(new Tuple <EventLog, T>(simpleLog, savedEntity));
                    }
                    else
                    {
                        outputContext.ResultCode = ETEMEnums.ResultEnum.Warning;
                        outputContext.Message    = String.Format(BaseHelper.GetCaptionString("Entity_Not_Found_By_ID"), Constants.INVALID_ID);
                    }
                }
                else
                {
                    outputContext.Message    = BaseHelper.GetCaptionString("Entity_is_not_created");
                    outputContext.ResultCode = ETEMEnums.ResultEnum.Error;
                    outputContext.EntityID   = Constants.INVALID_ID_STRING;

                    if (string.IsNullOrEmpty(this.EntitySetName))
                    {
                        outputContext.Message = BaseHelper.GetCaptionString("EntitySetName_is_not_set");
                    }

                    if (entity is IModifiable)
                    {
                        ((IModifiable)entity).SetCreationData(outputContext);
                    }

                    dbContext.AddObject(this.EntitySetName, entity);

                    try
                    {
                        dbContext.SaveChanges();
                    }
                    catch (Exception ex)
                    {
                        BaseHelper.Log("Грешка в BaseClassBL.EntitySave() - Create");
                        BaseHelper.Log(ex.Message);
                        BaseHelper.Log(ex.StackTrace);
                    }

                    outputContext.ActionName = Constants.ACTION_INSERT;
                    outputContext.ResultCode = ETEMEnums.ResultEnum.Success;
                    outputContext.EntityID   = entity.EntityID.ToString();
                    outputContext.listKvEntityID.Add(new KeyValuePair <string, int>(EntitySetName, entity.EntityID));
                    outputContext.Message = BaseHelper.GetCaptionString("Entity_is_created_successful");

                    EventLog simpleLog = MakeEventLog(outputContext, entity);

                    itemsToLog.Add(new Tuple <EventLog, T>(simpleLog, entity));
                }
            }


            var     application = System.Web.HttpContext.Current.Application;
            Setting setting     = new Setting();

            Dictionary <string, Setting> dictionarySetting = new Dictionary <string, Setting>();

            if (application != null && application[Constants.APPLICATION_SETTING_LIST] != null)
            {
                dictionarySetting = application[Constants.APPLICATION_SETTING_LIST] as Dictionary <string, Setting>;

                if (dictionarySetting == null)
                {
                    setting = new Setting()
                    {
                        SettingName         = "Създаване на подробен лог в базата данни(YES|NO)",
                        SettingDescription  = "Създаване на подробен лог в базата данни(YES|NO)",
                        SettingIntCode      = ETEMEnums.AppSettings.MakeLogInDB.ToString(),
                        SettingValue        = "YES",
                        SettingDefaultValue = "YES",
                        SettingClass        = ETEMEnums.AppSettingsClass.String.ToString()
                    };

                    dictionarySetting.Add(ETEMEnums.AppSettings.MakeLogInDB.ToString(), setting);
                }
            }
            else
            {
                setting = new Setting()
                {
                    SettingName         = "Създаване на подробен лог в базата данни(YES|NO)",
                    SettingDescription  = "Създаване на подробен лог в базата данни(YES|NO)",
                    SettingIntCode      = ETEMEnums.AppSettings.MakeLogInDB.ToString(),
                    SettingValue        = "YES",
                    SettingDefaultValue = "YES",
                    SettingClass        = ETEMEnums.AppSettingsClass.String.ToString()
                };
                dictionarySetting.Add(ETEMEnums.AppSettings.MakeLogInDB.ToString(), setting);
            }

            setting = dictionarySetting.Where(k => k.Key == ETEMEnums.AppSettings.MakeLogInDB.ToString()).FirstOrDefault().Value;

            if (setting.SettingValue == "YES")
            {
                if (itemsToLog.Count > 0)
                {
                    Thread t = new Thread(() => MakeFullDbLog(itemsToLog));
                    t.Start();
                }
            }

            return(outputContext);
        }
Пример #3
0
        public virtual CallContext EntityDelete <E>(List <T> entities, CallContext inputContext)
        {
            CallContext outputContext = new CallContext();

            outputContext.CurrentConsumerID = inputContext.CurrentConsumerID;
            outputContext.ResultCode        = ETEMEnums.ResultEnum.Success;
            // outputContext.securitySettings = inputContext.securitySettings;
            outputContext.ActionName = Constants.ACTION_DELETE;

            try
            {
                SetCallContextDataFromSession(outputContext);

                //outputContext.CurrentConsumerNames = props.PersonTwoNamePlusTitle;
                //outputContext.CurrentConsumerSessionId = props.SessionID;
                //outputContext.CurrentConsumerID = props.IdUser;
                //
            }
            catch (Exception ex)
            {
                outputContext.CurrentConsumerID = inputContext.CurrentConsumerID;
                BaseHelper.Log("Грешка създаване на обекта сесия в модела на приложението!");
                BaseHelper.Log(ex.Message);
            }

            List <Tuple <EventLog, T> > itemsToLog = new List <Tuple <EventLog, T> >();

            if (entities.Count > 0)
            {
                for (int i = 0; i < entities.Count; i++)
                {
                    var entity = entities[i];
                    if (!HasUserActionPermission(entity, outputContext, inputContext))
                    {
                        return(outputContext);
                    }

                    if (entity != null && entity.EntityID != Constants.INVALID_ID_ZERO && entity.EntityID != Constants.INVALID_ID)
                    {
                        savedEntity = GetEntityById(entity.EntityID);

                        if (savedEntity != null)
                        {
                            outputContext.EntityID = savedEntity.EntityID.ToString();

                            outputContext.Message    = BaseHelper.GetCaptionString("Entity_is_not_deleted");
                            outputContext.ResultCode = ETEMEnums.ResultEnum.Error;


                            dbContext.DeleteObject(savedEntity);

                            dbContext.SaveChanges();

                            outputContext.listKvEntityID.Add(new KeyValuePair <string, int>(EntitySetName, entity.EntityID));
                            outputContext.Message    = BaseHelper.GetCaptionString("Entity_is_deleted_successful");
                            outputContext.ResultCode = ETEMEnums.ResultEnum.Success;

                            EventLog simpleLog = MakeEventLog(outputContext, savedEntity);
                            itemsToLog.Add(new Tuple <EventLog, T>(simpleLog, entity));
                        }
                        else
                        {
                            outputContext.ResultCode = ETEMEnums.ResultEnum.Warning;
                            outputContext.Message    = String.Format(BaseHelper.GetCaptionString("Entity_Not_Found_By_ID"), Constants.INVALID_ID);
                        }
                    }
                    else
                    {
                        outputContext.Message    = BaseHelper.GetCaptionString("Entity_is_not_created");
                        outputContext.ResultCode = ETEMEnums.ResultEnum.Error;
                        outputContext.EntityID   = Constants.INVALID_ID_STRING;
                    }
                }


                if (itemsToLog.Count > 0)
                {
                    Thread t = new Thread(() => MakeFullDbLog(itemsToLog));
                    t.Start();
                }

                return(outputContext);
            }
            else
            {
                outputContext.ResultCode = ETEMEnums.ResultEnum.Error;
                outputContext.Message    = BaseHelper.GetCaptionString("The_list_of_entities_was_empty");
                return(outputContext);
            }
        }
Пример #4
0
        protected override void OnInit(EventArgs e)
        {
            LogDebug("GeneralPage OnInit");
            this.BaseHelperObj = new ETEMModel.Helpers.BaseHelper();
            this.AdminClientRef = new Administration();
            this.CommonClientRef = new Common();
            this.EmployeClientRef = new EmployeRef();
            this.CostCalculationRef = new ETEMModel.Services.CostCalculation.CostCalculationRef();

            this.CallContext = new CallContext();

            this.FormContext = new FormContext();
            this.FormContext.RequestMeasure = new RequestMeasure(this.Page.GetType().FullName);

            this.FormContext.UserProps = this.UserProps;

            this.FormContext.DictionaryKeyValue = DictionaryKeyValue;
            this.FormContext.DictionaryKeyType = DictionaryKeyType;
            this.FormContext.DictionarySetting = DictionarySetting;

            AdminClientRef.DictionaryKeyType = DictionaryKeyType;
            AdminClientRef.DictionaryKeyValue = DictionaryKeyValue;


            this.FormContext.DictionaryPermittedActionSetting = DictionaryPermittedActionSetting;

            //Функционалност за разкрептиране на криптираните ключове в QueryString_а
            if (Request.QueryString.Count > 0)
            {
                string rawQueryString = System.Web.HttpUtility.UrlDecode(Request.RawUrl.Substring(Request.RawUrl.IndexOf('?') + 1));

                string queryString = "";

                if (rawQueryString.IndexOf("Cript=false") == -1)
                {
                    queryString = ETEMModel.Helpers.BaseHelper.Decrypt(rawQueryString);
                }
                else
                {
                    queryString = rawQueryString;
                }

                string val;
                string key;

                string[] keys_values = queryString.Split('&');

                foreach (string key_value in keys_values)
                {
                    string[] kv = key_value.Split('=');

                    key = kv[0];
                    val = kv[1];

                    this.FormContext.QueryString.Add(key, val);
                }
            }

            if (userProps != null)
            {
                userProps.LastRequestDateTime = DateTime.Now;
                userProps.Page = this.Page.GetType().FullName;
            }



            base.OnInit(e);
        }