Esempio n. 1
0
        public static EmployeeAuthtorizationRequest ToEntity(this EmployeeAuthtorization request, Docs docs)
        => new EmployeeAuthtorizationRequest
        {
            EmployeeAuthorizationId   = request.EmployeeAuthorizationId,
            EmployeeAuthorizationName = request.EmployeeAuthorizationName,
            EmployeeId          = request.EmployeeId,
            SiteId              = request.SiteId,
            DateFrom            = request.DateFrom,
            DateTo              = request.DateTo,
            Comment             = request.Comment,
            AuthorizationTypeId = request.AuthorizationTypeId,
            AuthorizationType   = request.AuthorizationType,

            Employee = request.Employee,
            Site     = request.Site,

            uri        = docs == null ? null : docs.DocumentPath,
            UserInsert = request.UserInsert,
            DateInsert = request.DateInsert,
            UserUpdate = request.UserUpdate,
            DateUpdate = request.DateUpdate,
            State      = request.State,
        };
        // => dbContext.EmployeeWorkPermit.AsQueryable().Where(item => item.EmployeeId == entity.EmployeeId).Include(x => x.Site);

        public static IQueryable <EmployeeAuthtorizationRequest> GetEmployeeAuthtorizationByEmployeeIdAsync(this MastpenBitachonDbContext dbContext, EmployeeAuthtorization entity)
        {
            string tableName = GetTableNameByType(dbContext, typeof(EmployeeAuthtorization)).Result;

            // Get query from DbSet
            var query = from tr in dbContext.EmployeeAuthtorization
                        .Include(x => x.Site)
                        .Include(x => x.AuthorizationType)
                        .Where(item => item.EmployeeId == entity.EmployeeId)
                        .AsQueryable()

                        join docs in dbContext.Docs
                        .Where(a => a.EntityTypeId == dbContext.EntityType.FirstOrDefault(item => item.EntityTypeName == tableName).EntityTypeId)
                        .Where(a => a.DocumentTypeId == (int)DocumentType.Authtorization)
                        on tr.EmployeeAuthorizationId equals docs.EntityId into docs
                        from x_docs in docs.DefaultIfEmpty()

                        select tr.ToEntity(x_docs);

            return(query);
        }
Esempio n. 3
0
        // POST
        public async Task <SingleResponse <EmployeeAuthtorization> > CreateEmployeeAuthtorizationAsync(EmployeeAuthtorization employeeAuthtorization)
        {
            var response = new SingleResponse <EmployeeAuthtorization>();

            DbContext.Add(employeeAuthtorization, UserInfo);

            await DbContext.SaveChangesAsync();

            response.Model = employeeAuthtorization;

            return(response);
        }