Exemplo n.º 1
0
 public override void Configure()
 {
     using (EntitiesModel context = new EntitiesModel())
     {
         IEntityHelperManager entityHelperManager = this.Parent.EntityHelperManager;
         IList<MetaEnt> entities = context.GetAll<MetaEnt>().ToList();
         foreach (MetaEnt ent in entities)
         {
             EntityHelper helper = entityHelperManager.GetEntityHelperByName(StringUtil.Pascalize(ent.PhysicalName));
             if (helper != null)
             {
                 MetaEntity entity = new MetaEntity();
                 entity.EntityType = helper.EntityType;
                 entity.EntId = ent.EntId;
                 entity.EntityName = ent.LogicalName;
                 if (ent.AuditMode.Equals("NONE"))
                 {
                     entity.AuditType = AuditType.None;
                 }
                 else if (ent.AuditMode.Equals("SIMPLE"))
                 {
                     entity.AuditType = AuditType.Simple;
                 }
                 else if (ent.AuditMode.Equals("FULL"))
                 {
                     entity.AuditType = AuditType.Complete;
                 }
                 metaEntities.Add(entity.EntityType, entity);
                 metaEntitiesByKey.Add(entity.EntId, entity);
             }
         }
     }
 }
        /// <summary>
        /// Calculates the remaining minutes for the current month for the specified user.
        /// </summary>
        /// <param name="userId">The user identifier.</param>
        /// <returns></returns>
        public int Calculate(long userId)
        {
            using (EntitiesModel context = new EntitiesModel())
            {
                IList<short> minutes = (from allocation in context.WebAllocations
                                        where (allocation.UserId == userId) && (allocation.AllocationDate.Month == DateTime.UtcNow.Month)
                                        select allocation.Minutes).ToList();
                long totalMinutes = 0;
                foreach (short minute in minutes)
                {
                    totalMinutes += minute;
                }
                long officeMinutes = (from user in context.WebUsers
                                     join office in context.WebOffices on user.OfficeId equals office.OfficeId
                                     join times in context.WebOfficeTimePerMonths on office.OfficeId equals times.OfficeId
                                     where times.Month == DateTime.UtcNow.Month
                                     select times.Minutes).FirstOrDefault();
                long workingPercent = (from user in context.WebUsers
                             where user.UserId == userId
                             select user.WorkingPercent).FirstOrDefault();

                return Convert.ToInt32(( officeMinutes * workingPercent / 100) - totalMinutes);
            }
        }