protected virtual void OnValuesChanged(SamsaraEntityChooserValuesChangedEventArgs <T> e)
        {
            switch (this.controlType)
            {
            case SamsaraEntityChooserControlTypeEnum.Single:
                this.suceEntities.Value = null;
                break;

            case SamsaraEntityChooserControlTypeEnum.Multiple:
                if (e.NewValues != null && e.NewValues.Count > 0)
                {
                    this.suceEntities.Value = EntitiesUtil.GetPrimaryKeyPropertyValues <T>(e.NewValues);
                }
                else
                {
                    this.suceEntities.Value = new object[] { -1 };
                }
                break;

            default:
                throw new NotImplementedException();
            }

            if (this.ValueChanged != null)
            {
                this.ValuesChanged(this, e);
            }
        }
        public override void SaveEntity()
        {
            this.commissionPayment.Comments      = this.frmCommissionPayment.txtDetComments.Value as string;
            this.commissionPayment.Amount        = Convert.ToDecimal(this.frmCommissionPayment.txtDetAmount.Value);
            this.commissionPayment.Month         = Convert.ToInt32(this.frmCommissionPayment.uceDetMonth.Value);
            this.commissionPayment.Year          = Convert.ToInt32(this.frmCommissionPayment.txtDetYear.Value);
            this.commissionPayment.IsSalesRetail = this.frmCommissionPayment.uchkDetIsSalesRetail.Checked;
            this.commissionPayment.StaffNames    = string.Join(", ",
                                                               this.frmCommissionPayment.sccDetStaff.Values.Select(x => x.Fullname).ToArray());

            foreach (CommissionPaymentStaff commissionPaymentStaff in this.commissionPayment.CommissionPaymentStaffs)
            {
                EntitiesUtil.SetAsDeleted(commissionPaymentStaff);
            }

            foreach (Staff staff in this.frmCommissionPayment.sccDetStaff.Values)
            {
                CommissionPaymentStaff commissionPaymentStaff = new CommissionPaymentStaff();

                commissionPaymentStaff.CommissionPayment = this.commissionPayment;
                commissionPaymentStaff.Staff             = staff;

                this.commissionPayment.CommissionPaymentStaffs.Add(commissionPaymentStaff);
            }

            this.srvCommissionPayment.SaveOrUpdate(this.commissionPayment);
        }
Exemplo n.º 3
0
        public override void SaveEntity()
        {
            this.service.ServiceAmount = Convert.ToDecimal(this.frmServicesManagement.txtDetServiceAmount.Value);
            this.service.ServiceNumber = Convert.ToInt32(this.frmServicesManagement.txtDetServiceNumber.Value);
            this.service.StaffNames    = string.Join(", ", this.frmServicesManagement.sccDetStaff.Values.Select(x => x.Fullname).ToArray());
            this.service.Authorized    = this.frmServicesManagement.uchkDetAuthorized.Checked;
            this.service.Processed     = this.frmServicesManagement.uchkDetProcessed.Checked;

            foreach (ServiceStaff serviceStaff in this.service.ServiceStaff)
            {
                EntitiesUtil.SetAsDeleted(serviceStaff);
            }

            foreach (Staff staff in this.frmServicesManagement.sccDetStaff.Values)
            {
                ServiceStaff serviceStaff = new ServiceStaff();

                serviceStaff.Service = service;
                serviceStaff.Staff   = staff;

                this.service.ServiceStaff.Add(serviceStaff);
            }

            this.srvService.SaveOrUpdate(this.service);
        }
        protected virtual void OnValueChanged(SamsaraEntityChooserValueChangedEventArgs <T> e)
        {
            switch (this.controlType)
            {
            case SamsaraEntityChooserControlTypeEnum.Single:
                if (e.NewValue != null)
                {
                    if (!EqualityComparer <T> .Default.Equals(this.value, e.NewValue))
                    {
                        this.suceEntities.Value = EntitiesUtil.GetPrimaryKeyPropertyValue <T>(e.NewValue);
                        if (this.suceEntities.SelectedIndex == -1)
                        {
                            this.suceEntities.Value = -1;
                        }
                    }
                }
                else
                {
                    this.suceEntities.Value = -1;
                }
                break;

            case SamsaraEntityChooserControlTypeEnum.Multiple:
                this.suceEntities.Value = null;
                break;

            default:
                throw new NotImplementedException();
            }

            if (this.ValueChanged != null)
            {
                this.ValueChanged(this, e);
            }
        }
Exemplo n.º 5
0
        public override SubCategory GetById(object Id)
        {
            var cat = CreateServiceEntity();

            EntitiesUtil.SetEntityId(cat, Id);
            cat.SubCategoryName.Value = this.GetType().Name;
            cat.CategoryId.Value      = 1;
            cat.CategoryTypeId.Value  = 1;
            return(cat);
        }
Exemplo n.º 6
0
        public virtual void Delete <T>(T entity)
        {
            if (entity.GetType().IsSubclassOf(typeof(BaseEntity)))
            {
                (entity as BaseEntity).Deleted   = true;
                (entity as BaseEntity).Activated = false;

                EntitiesUtil.ProcessAuditProperties(entity, this.GetServerDateTime(), null, this.Session);
                this.HibernateTemplate.Update(entity);
            }
            else
            {
                this.HibernateTemplate.Delete(entity);
            }
        }
Exemplo n.º 7
0
        public static IEnumerable <T> MapEntity <T>(T Entity, dynamic DapperResult)
        {
            var Output   = new List <T>();
            var PropsOfT = Entity.GetType().GetProperties();

            foreach (var row in DapperResult)
            {
                T Ent = (T)Activator.CreateInstance(Entity.GetType());
                foreach (var p in PropsOfT)
                {
                    var data      = (IDictionary <string, object>)row;
                    var DataInRow = data[p.Name];
                    if (DataInRow == null)
                    {
                        continue;
                    }
                    var TypedValue = EntitiesUtil.ChangeType(DataInRow, p.PropertyType);
                    p.SetValue(Ent, TypedValue, null);
                }
                Output.Add(Ent);
            }
            return(Output);
        }
Exemplo n.º 8
0
 public virtual void Update <T>(T entity)
 {
     EntitiesUtil.ProcessAuditProperties(entity, this.GetServerDateTime(), null, this.Session);
     this.HibernateTemplate.Update(entity);
 }
Exemplo n.º 9
0
 public virtual void Save(object entity)
 {
     EntitiesUtil.ProcessAuditProperties(entity, this.GetServerDateTime(), null, this.Session);
     this.HibernateTemplate.Save(entity);
 }
Exemplo n.º 10
0
            //[Test]
            public void edits_are_executed_()
            {
                Moq.Mock <SubCategoryEdits> _edit;

                Moq.Mock <SubCategoriesService> _service;

                /*
                 * public SubCategoriesService(IRepository<SubCategory> subCategoryRepository
                 *                      , IServiceEntityEdit<SubCategory> Edits
                 *                      )
                 */

                var context = new ReposContext("ReposContext");


                _edit = new Moq.Mock <SubCategoryEdits>(_Context.Object);

                var scRepos = new EfRepository <SubCategory>(G_mockUnitOfWork.Object);

                //var _scRepos = new Mock<EfRepository<SubCategory>>(context); //.Object) { CallBase = true };

                var sc = new TestSubCategory
                {
                    Id = 1,
                    SubCategoryName = new DomainEntityTypeString {
                        Value = "Default"
                    }
                };

                var dataCategories = new List <Category>
                {
                    new TestCategory {
                        CategoryName = new DomainEntityTypeString {
                            Value = "AAA"
                        }
                    },
                    new TestCategory {
                        CategoryName = new DomainEntityTypeString {
                            Value = "BBB"
                        }
                    },
                    new TestCategory {
                        CategoryName = new DomainEntityTypeString {
                            Value = "ZZZ"
                        }
                    }
                }.AsQueryable();

                var mockSet = new Mock <DbSet <SubCategory> >()
                {
                    CallBase = true
                };

                var DB = new TestDbSet <SubCategory>(); //                   DbSet<SubCategory>();

                mockSet.As <IQueryable <SubCategory> >().Setup(m => m.Provider).Returns(dataCategories.Provider);
                mockSet.As <IQueryable <SubCategory> >().Setup(m => m.Expression).Returns(dataCategories.Expression);
                mockSet.As <IQueryable <SubCategory> >().Setup(m => m.ElementType).Returns(dataCategories.ElementType);
                //   mockSet.As<IQueryable<SubCategory>>().Setup(m => m.GetEnumerator()).Returns(o => dataCategories.GetEnumerator());


                //_Context.Setup(m => m.Set<SubCategory>()).Returns(DB);

                var MockDbContext = EntityFrameworkMockHelper.GetMockContext <IDbContext>();

                MockDbContext.CallBase = true;


                MockDbContext.Setup(m => m.Set <SubCategory>()).Returns(DB);

                var _scRepos = new Mock <IRepository <SubCategory> >()
                {
                    CallBase = true
                };

                // var mockSet = new Mock<DbSet<SubCategory>>() { CallBase = true };

                var x_scRepos = new Mock <EfRepository <SubCategory> >(G_mockUnitOfWork.Object)
                {
                    CallBase = true
                };

                x_scRepos.Setup(s => s.Add(It.IsAny <SubCategory>()));
                x_scRepos.Setup(s => s.ModifiedEntities).Returns(It.IsAny <EntityRules>());


                var scReposx = new EfRepository <SubCategory>(G_mockUnitOfWork.Object);

                var testRulesFactory = new TestRulesFactory();

                _service = new Moq.Mock <SubCategoriesService>(x_scRepos.Object //_mockSubCategoryRepository.Object
                                                               , _edit.Object, testRulesFactory)
                {
                    CallBase = true
                };


                var cat = EntitiesUtil.CreateEntity <SubCategory>();


                _edit.Setup(s => s.SetEntitiesDefaults(cat));

                var Model = new SubCategoryModel
                {
                    SubCategoryName
                        = new DomainEntityTypeString {
                        Value = "Defaultx", Attributes = null
                        }
                };

                //   _service.Object.CreateServiceEntity();

                ModelStateDictionary modelState = new ModelStateDictionary();

                //  _service.Object.Save();

                var subCategoryEntity = new TestSubCategory
                {
                    Id = 1
                    ,
                    SubCategoryName = new DomainEntityTypeString {
                        Value = "Default"
                    }
                };



                _service.Object.Add(subCategoryEntity);

                _service.Object.Verify(modelState);

                // _edit.Object.SetEntitiesDefaults(cat);

                //   _edit.Verify(s => s.SetEntitiesDefaults(cat), Times.Once);
            }