Ejemplo n.º 1
0
        /// <summary>
        /// Returns new workplace position.
        /// </summary>
        /// <param name="type">New workplace type.</param>
        /// <returns>New workplace position.</returns>
        protected int GetNewWorkplacePosition(WorkplaceType type)
        {
            var workplacePositions = GetWorkplacesByType(type).Select(w => w.Position);

            if (!workplacePositions.Any())
            {
                return(0);
            }
            return(workplacePositions.Max() + 1);
        }
Ejemplo n.º 2
0
        private Guid?GetWorkplaceTypeId(WorkplaceType Type)
        {
            var typeEsq = new EntitySchemaQuery(_userConnection.EntitySchemaManager, "SysWorkplaceType")
            {
                Cache         = _userConnection.ApplicationCache.WithLocalCaching("SysWorkplaceType"),
                CacheItemName = "WorkplaceType_Code"
            };
            string           idColumnName     = typeEsq.AddColumn("Id").Name;
            string           codeColumnName   = typeEsq.AddColumn("Code").Name;
            EntityCollection entityCollection = typeEsq.GetEntityCollection(_userConnection);
            var workplaceType = entityCollection.Where(t => t.GetTypedColumnValue <int>(codeColumnName) == (int)Type)
                                .FirstOrDefault();

            return(workplaceType?.GetTypedColumnValue <Guid>(idColumnName));
        }
Ejemplo n.º 3
0
        /// <inheritdoc />
        public Workplace CreateWorkplace(string name, WorkplaceType type)
        {
            var position  = GetNewWorkplacePosition(type);
            var workplace = new Workplace(Guid.NewGuid(), name, type)
            {
                Position = position
            };

            if (_workplaceRepository.SaveWorkplace(workplace))
            {
                return(workplace);
            }
            var message = GetWorkplaceExceptionMessage("WorkplaceCreateFailed");

            throw new WorkplaceCreateFailedException(message);
        }
Ejemplo n.º 4
0
        /// <inheritdoc />
        public IEnumerable <Workplace> GetWorkplacesByType(WorkplaceType type)
        {
            var result = _workplaceRepository.GetAll().Where(w => w.Type == type);

            return(result);
        }