Exemple #1
0
        public async Task <ResponseDTO> ValidateEntityRegister(RegisterProductRequest request)
        {
            Expression <Func <ProductDTO, bool> > queryFilter = p => true;
            var result = "";

            queryFilter = queryFilter.And(p => p.Code == request.Code);
            queryFilter = queryFilter.Or(p => p.RowStatus == true && (p.Name == request.Name || p.ShortName == request.ShortName));

            var product = await _productDataAcces.FirstOrDefaultAsync(queryFilter);

            if (product != null)
            {
                result = "Product already Exists";
            }

            var response = new ResponseDTO()
            {
                IsValid  = string.IsNullOrEmpty(result),
                Messages = new List <ApplicationMessage>()
            };

            response.Messages.Add(new ApplicationMessage()
            {
                Key     = string.IsNullOrEmpty(result) ? "Ok" : "Error",
                Message = result
            });

            return(response);
        }
        public async Task <ResponseDTO <ContractRegisterRequest> > GetLastCode(string contractCode)
        {
            List <OrderExpression <ContractRegisterRequest> > orderExpressionList = new List <OrderExpression <ContractRegisterRequest> >();

            orderExpressionList.Add(new OrderExpression <ContractRegisterRequest>(OrderType.Desc, p => p.ContractCode));
            Expression <Func <ContractRegisterRequest, bool> > queryFilter = c => c.ContractCode.Contains(contractCode);
            var mainTenant = await _contractDataAccess.FirstOrDefaultAsync(queryFilter, orderExpressionList.ToArray());

            return(ResponseBuilder.Correct(mainTenant));
        }
Exemple #3
0
        public async Task <ResponseDTO <PeriodDTO> > GetPeriodByCodeAsync(string code)
        {
            Expression <Func <PeriodDTO, bool> > queryFilter = c => true;

            if (!string.IsNullOrEmpty(code))
            {
                queryFilter = queryFilter.And(p => p.Code == code);
            }

            var period = await _periodDataAccess.FirstOrDefaultAsync(queryFilter);

            return(ResponseBuilder.Correct(period));
        }
Exemple #4
0
        public async Task <ResponseDTO <MainTenantDTO> > GetById(int?id)
        {
            Expression <Func <MainTenantDTO, bool> > queryFilter = c => true;

            if (id.HasValue)
            {
                queryFilter = queryFilter.And(p => p.TenantId == id.GetValueOrDefault(0));
            }

            var mainTenant = await _mainTenantSearchDataAccess.FirstOrDefaultAsync(queryFilter);

            return(ResponseBuilder.Correct(mainTenant));
        }
        public async Task <ResponseDTO <List <ModuleTreeDTO> > > GetRoleTree(string roleCode)
        {
            // ModuleTreeDTO
            var role        = (await _rolDataAccess.FirstOrDefaultAsync(x => x.Code == roleCode && x.RowStatus));
            var permissions = (await _permissionDataAccess.ListAsync(x => x.AmigoTenantTRoleId == role.AmigoTenantTRoleId)).Select(x => x.ActionCode).ToList();

            var modules = (await _moduleDataAcces.ListAllAsync()).ToList();
            var actions = (await _actionDataAcces.ListAllAsync()).ToList();

            var tree = GetModulesForParent(null, modules, actions, permissions);

            return(ResponseBuilder.Correct(tree));
        }
        private async Task <HouseDTO> GetHouseById(int id)
        {
            Expression <Func <HouseDTO, bool> > queryFilter = c => true;

            queryFilter = queryFilter.And(p => p.HouseId == id);

            var house = await _houseDataAccess.FirstOrDefaultAsync(queryFilter);

            return(house);
        }
        public async Task <ResponseDTO> ValidateCellphoneAndUser(string cellphoneNumber, int?userid)
        {
            Expression <Func <DeviceDTO, bool> > queryFilter = p => true;
            var result = "";

            if (userid.HasValue)
            {
                queryFilter = queryFilter.And(p => p.CellphoneNumber != cellphoneNumber.Trim());
                queryFilter = queryFilter.And(p => p.AssignedAmigoTenantTUserId == userid);
                var device = await _deviceDataAccess.FirstOrDefaultAsync(queryFilter);

                if (device != null)
                {
                    result = "The cellphone has another user associated or the user is assigned to another device";
                }
                else
                {
                    Expression <Func <DeviceDTO, bool> > queryFilter1 = p => true;
                    queryFilter1 = queryFilter1.And(p => p.CellphoneNumber != cellphoneNumber.Trim());
                    queryFilter1 = queryFilter1.And(p => p.AssignedAmigoTenantTUserId == userid);
                    device       = await _deviceDataAccess.FirstOrDefaultAsync(queryFilter1);

                    if (device != null)
                    {
                        result = "The user has another device associated";
                    }
                }
            }

            var response = new ResponseDTO()
            {
                IsValid  = string.IsNullOrEmpty(result),
                Messages = new List <ApplicationMessage>()
            };

            response.Messages.Add(new ApplicationMessage()
            {
                Key     = string.IsNullOrEmpty(result)? "Ok":"Error",
                Message = result
            });

            return(response);
        }
        public async Task <AmigoTenantTUserBasicDTO> GetBaseUserInfoById(int amigoTenantTUserId)
        {
            Expression <Func <AmigoTenantTUserBasicDTO, bool> > queryFilter = p => true;

            queryFilter = queryFilter.And(p => p.AmigoTenantTUserId == amigoTenantTUserId);

            var result = await _userBasicDataAccess.FirstOrDefaultAsync(queryFilter);

            return(result);
        }
Exemple #9
0
        public async Task <CostCenterTypeAheadDTO> SearchCostCenterByNameAsync(string name)
        {
            Expression <Func <CostCenterDTO, bool> > queryFilter = c => true;

            if (!string.IsNullOrEmpty(name))
            {
                queryFilter = queryFilter.And(p => p.Name.Contains(name));
            }
            var typeAheadElement = new CostCenterTypeAheadDTO();
            var location         = (await _costCenterDataAccess.FirstOrDefaultAsync(queryFilter));

            if (location != null)
            {
                typeAheadElement.CostCenterIdId = location.CostCenterId;
                typeAheadElement.Code           = location.Code;
                typeAheadElement.Name           = location.Name;
            }

            return(typeAheadElement);
        }
        public async Task <ResponseDTO <AmigoTenantTRoleBasicDTO> > GetAmigoTenantTRoleBasicByIdAsync(AmigoTenantTRoleSearchRequest search)
        {
            Expression <Func <AmigoTenantTRoleBasicDTO, bool> > queryFilter = p => true;

            if (search.AmigoTenantTRoleId > 0)
            {
                queryFilter = queryFilter.And(p => p.AmigoTenantTRoleId == search.AmigoTenantTRoleId);
            }
            var result = await _dataAccessBasic.FirstOrDefaultAsync(queryFilter);

            return(ResponseBuilder.Correct(result));
        }
        public async Task <ResponseDTO <ExpenseDetailRegisterRequest> > GetDetailByExpenseDetailIdAsync(int?id)
        {
            Expression <Func <ExpenseDetailRegisterRequest, bool> > queryFilter = c => true;

            if (id.HasValue)
            {
                queryFilter = queryFilter.And(p => p.ExpenseId == id);
            }

            var expense = await _expenseDetailDataAccess.FirstOrDefaultAsync(queryFilter);

            return(ResponseBuilder.Correct(expense));
        }
        public async Task <ResponseDTO <RentalApplicationRegisterRequest> > GetByIdAsync(int?id)
        {
            Expression <Func <RentalApplicationRegisterRequest, bool> > queryFilter = c => true;

            if (id.HasValue)
            {
                queryFilter = queryFilter.And(p => p.RentalApplicationId == id);
            }

            var rentalApplication = await _rentalApplicationDataAccess.FirstOrDefaultAsync(queryFilter);

            return(ResponseBuilder.Correct(rentalApplication));
        }
        public async Task <AmigoTenantParameterDTO> GetAmigoTenantParameterByCodeAsync(string code)
        {
            Expression <Func <AmigoTenantParameterDTO, bool> > queryFilter = c => true;

            if (!string.IsNullOrEmpty(code))
            {
                queryFilter = queryFilter.And(p => p.Code == code);
            }

            var list = await _amigoTenantParameterDataAcces.FirstOrDefaultAsync(queryFilter);

            return(list);
        }
Exemple #14
0
        public async Task <ActivityTypeDTO> SearchActivityByCodeAsync(string code)
        {
            Expression <Func <ActivityTypeDTO, bool> > queryFilter = c => true;

            if (!string.IsNullOrEmpty(code))
            {
                queryFilter = queryFilter.And(p => p.Code == code);
            }

            var list = await _activityTypeDataAcces.FirstOrDefaultAsync(queryFilter);

            return(list);
        }
        public async Task <AmigoTenantTUserDTO> SearchUsersByIdAsync(UserSearchRequest search)
        {
            var queryFilter = GetQueryFilter(search);
            var result      = await _userDataAccess.FirstOrDefaultAsync(queryFilter);

            if (result != null)
            {
                await SetUserAdditionalInformation(result);
            }

            return(result);
        }
        public async Task <EntityStatusDTO> GetEntityStatusByEntityAndCodeAsync(string entityCode, string entityStatusCode)
        {
            Expression <Func <EntityStatusDTO, bool> > queryFilter = c => true;

            if (!string.IsNullOrEmpty(entityCode))
            {
                queryFilter = queryFilter.And(p => p.EntityCode == entityCode);
            }

            if (!string.IsNullOrEmpty(entityStatusCode))
            {
                queryFilter = queryFilter.And(p => p.Code == entityStatusCode);
            }

            var entityStatus = await _entityStatusDataAccess.FirstOrDefaultAsync(queryFilter);

            return(entityStatus);
        }
        public async Task <GeneralTableDTO> GetGeneralTableByEntityAndCodeAsync(string entityCode, string generalTableCode)
        {
            Expression <Func <GeneralTableDTO, bool> > queryFilter = c => true;

            if (!string.IsNullOrEmpty(entityCode))
            {
                queryFilter = queryFilter.And(p => p.TableName == entityCode);
            }

            if (!string.IsNullOrEmpty(generalTableCode))
            {
                queryFilter = queryFilter.And(p => p.Code == generalTableCode);
            }

            var generalTable = await _generalTableDataAccess.FirstOrDefaultAsync(queryFilter);

            return(generalTable);
        }
        public async Task <ResponseDTO <List <Last24HoursDTO> > > SearchAsync(Last24HoursRequest search)
        {
            //---------------------------------------------------------------------------------------------
            //----------------  Get driver's last 24 hours logs from AmigoTenant DB -------------------
            //---------------------------------------------------------------------------------------------
            var queryFilter = GetQueryFilter(search);
            IEnumerable <Last24HoursDTO> eventLogs;

            Expression <Func <Last24HoursDTO, object> > expressionReportedActivityDate = p => p.ReportedActivityDate;
            List <OrderExpression <Last24HoursDTO> >    orderExpressions = new List <OrderExpression <Last24HoursDTO> >();

            orderExpressions.Add(new OrderExpression <Last24HoursDTO>(OrderType.Desc, expressionReportedActivityDate));

            var mostRecent = await _last24HoursDataAccess.FirstOrDefaultAsync(queryFilter, orderExpressions.ToArray());

            if (mostRecent != null)
            {
                var before24Hours = mostRecent.ReportedActivityDate.Value.Subtract(new TimeSpan(24, 0, 0));
                eventLogs =
                    await
                    _last24HoursDataAccess.ListAsync(queryFilter.And(w => w.ReportedActivityDate >= before24Hours));

                //eventLogs = eventLogs.Select(s => s.);
                eventLogs.ToList().ForEach(x => x.Username = x.Username.ToUpper());

                var myGroup = eventLogs.GroupBy(
                    p => new
                {
                    p.AmigoTenantTUserId,
                    p.Username,
                    p.Latitude,
                    p.Longitude,
                    p.ChargeNo,
                    p.ChargeType,
                    p.ActivityTypeName,
                    p.ActivityTypeCode,
                    p.TractorNumber,
                    p.FirstName,
                    p.LastName,
                    p.ChassisNumber,
                    p.EquipmentNumber
                }

                    );
                eventLogs = myGroup
                            .Select(el => new Last24HoursDTO
                {
                    AmigoTenantTUserId       = el.Key.AmigoTenantTUserId,
                    Username                 = el.Key.Username,
                    Latitude                 = el.Key.Latitude,
                    Longitude                = el.Key.Longitude,
                    ChargeNo                 = el.Key.ChargeNo,
                    ChargeType               = el.Key.ChargeType,
                    ActivityTypeName         = el.Key.ActivityTypeName,
                    ActivityTypeCode         = el.Key.ActivityTypeCode,
                    TractorNumber            = el.Key.TractorNumber,
                    FirstName                = el.Key.FirstName,
                    LastName                 = el.Key.LastName,
                    ChassisNumber            = el.Key.ChassisNumber,
                    EquipmentNumber          = el.Key.EquipmentNumber,
                    ReportedActivityTimeZone = el.Last().ReportedActivityTimeZone,
                    ReportedActivityDate     = el.Last().ReportedActivityDate,
                    Product           = el.Last().Product,
                    Origin            = el.Last().Origin,
                    Destination       = el.Last().Destination,
                    ServiceName       = el.Last().ServiceName,
                    EquipmentTypeName = el.Last().EquipmentTypeName
                }).ToList().OrderByDescending(o => o.ReportedActivityDate);
            }
            else
            {
                List <Last24HoursDTO> res = new List <Last24HoursDTO>();
                return(ResponseBuilder.Correct(res));
            }

            //---------------------------------------------------------------------------------------------
            //----------------  Get driver's firstName/lastName from Identity server ----------------------
            //---------------------------------------------------------------------------------------------


            string usernameParameter = "username="******"api/Users/GetUser?" + usernameParameter);

            if (rspUserDetails.IsSuccessStatusCode)
            {
                var userDetailsJson = await rspUserDetails.Content.ReadAsStringAsync().ConfigureAwait(false);

                var user = JsonConvert.DeserializeObject <ResponseDTO <UserResponse> >(userDetailsJson);

                //----------------------------------------------------------------------
                //----------------------    merge with results list -------------------
                //----------------------------------------------------------------------
                int i = 0;
                foreach (var log in eventLogs)
                {
                    i++;
                    log.FirstName = user.Data.FirstName;
                    log.LastName  = user.Data.LastName;
                    log.Index     = i;
                }

                return(ResponseBuilder.Correct(eventLogs.ToList()));
            }
            else
            {
                throw new Exception("Amigo.Tenant.Application.Services.Tracking - Last24HoursService - SearchAsync - call to IdentityServerHttpClient api/Users/GetUsersDetails was not successful");
            }
        }
Exemple #19
0
        public async Task <ResponseDTO <PPDetailSearchByContractPeriodDTO> > CalculateLateFeeByContractAndPeriodAsync(PaymentPeriodSearchByContractPeriodRequest search)
        {
            Expression <Func <PPSearchByContractPeriodDTO, bool> > queryFilter = c => true;

            if (search.PeriodId.HasValue)
            {
                queryFilter = queryFilter.And(p => p.PeriodId == search.PeriodId);
            }
            if (search.ContractId.HasValue)
            {
                queryFilter = queryFilter.And(p => p.ContractId == search.ContractId);
            }

            var header = await _paymentPeriodSearchByContractDataAccess.FirstOrDefaultAsync(queryFilter);

            var lateFeePaymenType = await _generalTableApplicationService.GetGeneralTableByEntityAndCodeAsync(Constants.GeneralTableName.PaymentType, Constants.GeneralTableCode.PaymentType.LateFee);

            var concept = await _conceptApplicationService.GetConceptByCodeAsync(Constants.ConceptCode.LateFee);

            var entityStatusPayment = await _entityStatusApplicationService.GetEntityStatusByEntityAndCodeAsync(Constants.EntityCode.PaymentPeriod, Constants.EntityStatus.PaymentPeriod.Pending);

            var lateFeeDetail = new PPDetailSearchByContractPeriodDTO();

            if (header != null)
            {
                //var header = paymentsPeriod.FirstOrDefault();
                var delayDays = DateTime.Today.Subtract(header.PeriodDueDate.Value).TotalDays;

                queryFilter = queryFilter.And(p => p.PaymentTypeCode == Constants.GeneralTableCode.PaymentType.LateFee);
                var existLateFeeInDB = await _paymentPeriodSearchByContractDataAccess.FirstOrDefaultAsync(queryFilter);

                if (header != null)
                {
                    if (existLateFeeInDB == null && delayDays > 0)
                    {
                        lateFeeDetail.PaymentPeriodId         = -1;
                        lateFeeDetail.ContractId              = header.ContractId;
                        lateFeeDetail.PeriodId                = header.PeriodId;
                        lateFeeDetail.PaymentAmount           = 25 * (decimal?)delayDays;
                        lateFeeDetail.PaymentTypeId           = lateFeePaymenType.GeneralTableId;
                        lateFeeDetail.PaymentTypeValue        = lateFeePaymenType.Value;
                        lateFeeDetail.PaymentTypeCode         = lateFeePaymenType.Code;
                        lateFeeDetail.PaymentTypeName         = lateFeePaymenType.Code;
                        lateFeeDetail.PaymentPeriodStatusCode = Constants.EntityStatus.PaymentPeriod.Pending;
                        lateFeeDetail.PaymentPeriodStatusId   = entityStatusPayment.EntityStatusId;
                        lateFeeDetail.IsRequired              = false;
                        lateFeeDetail.IsSelected              = false;
                        lateFeeDetail.TableStatus             = DTOs.Requests.Common.ObjectStatus.Added;
                        lateFeeDetail.PaymentDescription      = lateFeePaymenType.Value;
                        lateFeeDetail.ConceptId               = concept.Data.ConceptId;
                        lateFeeDetail.TenantId                = header.TenantId;
                        lateFeeDetail.PaymentPeriodStatusName = Constants.EntityStatus.PaymentPeriodStatusName.Pending;
                        return(ResponseBuilder.Correct(lateFeeDetail));
                    }
                    else if (existLateFeeInDB != null)
                    {
                        var entity = _mapper.Map <PPSearchByContractPeriodDTO, PPDetailSearchByContractPeriodDTO>(existLateFeeInDB);
                        entity.PaymentAmount = 25 * (decimal?)delayDays;
                        entity.TableStatus   = DTOs.Requests.Common.ObjectStatus.Modified;
                        return(ResponseBuilder.Correct(entity));
                    }
                }
            }
            return(null);
        }