Example #1
0
        public void AddOrUpdate(ITenantModel model)
        {
            try
            {
                using (var ctx = new DBProjectEntities())
                {
                    var newObject = ctx.Najemcy.Find(model.Id);

                    if (newObject == null)
                    {
                        newObject = Mapper.ModelMapper.Mapper.Map <Najemcy>(model);
                        ctx.Najemcy.Add(newObject);
                    }
                    else
                    {
                        newObject.imie        = model.imie;
                        newObject.nazwisko    = model.nazwisko;
                        newObject.nr_telefonu = model.nr_telefonu;
                        newObject.PESEL       = model.PESEL;
                    }
                    ctx.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                Logger.Log(ex.Message);
            }
        }
        /// <summary>
        /// Tenant Add/Update
        /// </summary>
        /// <param name="model"></param>
        /// <returns>True if created, false if updated</returns>
        public bool TenantAddUpdate(ITenantModel model)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            if (model.Configuration == null)
            {
                model.Configuration = new List <KeyValuePair <string, string> >();
            }

            if (model.Contact == null)
            {
                model.Contact = new ContactBase();
            }

            if (model._id == Guid.Empty)
            {
                throw new ArgumentException($"A model must contain a `TenantId`", nameof(model));
            }

            bool exists = this.TenantExists(model._id);

            this._dataProvider.Write((T)model);
            return(exists);
        }
Example #3
0
        /// <summary>
        /// Instantiate an object and inject all dependencies into the properties that are ITenantModel <see cref="ITenantModel"/>
        /// </summary>
        /// <param name="subject"></param>
        /// <returns></returns>
        public static ITenantModel InjectTenantModelNamedInstance(ITenantModel subject)
        {
            var properties = subject.GetType().GetProperties();

            foreach (var property in properties)
            {
                if (IsATenantModelProperty(property))
                {
                    if (TenantContext.TenantKey != null)
                    {
                        subject = InjectTenantModel(subject, property);
                    }
                }
            }
            return(subject);
        }
Example #4
0
        private static ITenantModel InjectTenantModel(ITenantModel obj, PropertyInfo property)
        {
            if (IsATenantModelProperty(property))
            {
                string teantPropertyName = TenantContext.TenantKey + property.Name;

                try
                {
                    var pluginService = ObjectFactory.GetNamedInstance(typeof(ITenantModel), teantPropertyName) as ITenantModel;
                    if (pluginService != null)
                    {
                        property.SetValue(obj, pluginService, null);
                        InjectTenantModelNamedInstance(pluginService);
                    }
                }
                catch
                { }

                property.GetValue(obj, null);

                return(obj);
            }
            return(obj);
        }
Example #5
0
 public bool Remove(ITenantModel model)
 {
     return(Remove(model.Id));
 }