public async Task <ApiResponse> Handle(SaveExchangeRatesForAllOfficesCommand officeExchangeRateViewModel, CancellationToken cancellationToken)
        {
            ApiResponse response = new ApiResponse();

            List <ExchangeRateDetail> exchangeRateList = new List <ExchangeRateDetail>();

            try
            {
                if (officeExchangeRateViewModel.SaveForAllOffices)
                {
                    exchangeRateList = await _dbContext.ExchangeRateDetail.Where(x => x.IsDeleted == false && x.Date.Date == officeExchangeRateViewModel.GenerateExchangeRateModel.FirstOrDefault().Date.Date).ToListAsync();

                    if (exchangeRateList.Any())
                    {
                        foreach (ExchangeRateDetail item in exchangeRateList)
                        {
                            item.Rate = (decimal)officeExchangeRateViewModel.GenerateExchangeRateModel.FirstOrDefault(x => x.ToCurrencyId == item.ToCurrency && x.FromCurrencyId == item.FromCurrency).Rate;
                        }

                        _dbContext.ExchangeRateDetail.UpdateRange(exchangeRateList);
                        _dbContext.SaveChanges();
                    }
                }
                else
                {
                    exchangeRateList = await _dbContext.ExchangeRateDetail.Where(x => x.IsDeleted == false && x.Date.Date == officeExchangeRateViewModel.GenerateExchangeRateModel.FirstOrDefault().Date.Date&& x.OfficeId == officeExchangeRateViewModel.OfficeId).ToListAsync();

                    if (exchangeRateList.Any())
                    {
                        foreach (ExchangeRateDetail item in exchangeRateList)
                        {
                            item.Rate = (decimal)officeExchangeRateViewModel.GenerateExchangeRateModel.FirstOrDefault(x => x.ToCurrencyId == item.ToCurrency && x.FromCurrencyId == item.FromCurrency).Rate;
                        }

                        _dbContext.ExchangeRateDetail.UpdateRange(exchangeRateList);
                        _dbContext.SaveChanges();
                    }
                }

                response.StatusCode = StaticResource.successStatusCode;
                response.Message    = "Exchange rates updated successfully!!!";
            }
            catch (Exception ex)
            {
                response.StatusCode = StaticResource.failStatusCode;
                response.Message    = StaticResource.SomethingWrong + ex.Message;
            }

            return(response);
        }
示例#2
0
        public async Task <ApiResponse> Handle(DeleteExchangeRatesCommand command, CancellationToken cancellationToken)
        {
            ApiResponse response = new ApiResponse();

            try
            {
                if (command.ExchangeRateDate == null)
                {
                    throw new Exception("Exchange Rate Date can't be null");
                }

                var exchangeRateVerification = await _dbContext.ExchangeRateVerifications
                                               .FirstOrDefaultAsync(x => x.IsDeleted == false &&
                                                                    x.Date.Date == command.ExchangeRateDate.Date);

                if (exchangeRateVerification != null)
                {
                    exchangeRateVerification.IsDeleted    = true;
                    exchangeRateVerification.ModifiedDate = DateTime.UtcNow;
                    exchangeRateVerification.ModifiedById = command.ModifiedById;
                    _dbContext.Update(exchangeRateVerification);
                    _dbContext.SaveChanges();
                }

                List <ExchangeRateDetail> exchangeRateList = await _dbContext.ExchangeRateDetail.Where(x => x.IsDeleted == false && x.Date.Date == command.ExchangeRateDate).ToListAsync();

                if (exchangeRateList.Any())
                {
                    foreach (ExchangeRateDetail exchangeRate in exchangeRateList)
                    {
                        exchangeRate.IsDeleted    = true;
                        exchangeRate.ModifiedById = command.ModifiedById;
                        exchangeRate.ModifiedDate = DateTime.UtcNow;
                    }
                    _dbContext.UpdateRange(exchangeRateList);
                    _dbContext.SaveChanges();
                }

                response.StatusCode = StaticResource.successStatusCode;
                response.Message    = "Exchange rates deleted successfully";
            }
            catch (Exception ex)
            {
                response.StatusCode = StaticResource.failStatusCode;
                response.Message    = StaticResource.SomethingWrong + ex.Message;
            }

            return(response);
        }
示例#3
0
        public async Task <ApiResponse> Handle(DeleteProjectAreaCommand request, CancellationToken cancellationToken)
        {
            ApiResponse response = new ApiResponse();

            try
            {
                var ProjectSectorInfo = await _dbContext.ProjectArea.FirstOrDefaultAsync(x => x.IsDeleted == false && x.ProjectAreaId == request.ProjectAreaId && x.ProjectId == request.ProjectId);

                if (ProjectSectorInfo != null)
                {
                    ProjectSectorInfo.IsDeleted    = true;
                    ProjectSectorInfo.ModifiedById = request.ModifiedById;
                    ProjectSectorInfo.ModifiedDate = request.ModifiedDate;
                    _dbContext.SaveChanges();
                    response.StatusCode = StaticResource.successStatusCode;
                    response.Message    = "Success";
                }
            }
            catch (Exception ex)
            {
                response.StatusCode = StaticResource.failStatusCode;
                response.Message    = StaticResource.SomethingWrong + ex.Message;
            }
            return(response);
        }
示例#4
0
        public async Task <ApiResponse> Handle(AddEditDonorDetailsCommand request, CancellationToken cancellationToken)
        {
            ApiResponse response = new ApiResponse();

            try
            {
                if (request.DonorId == 0)
                {
                    DonorDetail obj = _mapper.Map <AddEditDonorDetailsCommand, DonorDetail>(request);
                    obj.Name               = request.Name;
                    obj.ContactPerson      = request.ContactPerson;
                    obj.ContactDesignation = request.ContactDesignation;
                    obj.ContactPersonEmail = request.ContactPersonEmail;
                    obj.ContactPersonCell  = request.ContactPersonCell;
                    obj.IsDeleted          = false;
                    obj.CreatedById        = request.CreatedById;
                    obj.CreatedDate        = DateTime.UtcNow;

                    await _dbContext.DonorDetail.AddAsync(obj);

                    await _dbContext.SaveChangesAsync();

                    response.data.DonorDetailById = obj;
                    response.data.TotalCount      = await _dbContext.DonorDetail.Where(x => x.IsDeleted == false).AsNoTracking().CountAsync();
                }
                else
                {
                    var existRecord = await _dbContext.DonorDetail.FirstOrDefaultAsync(x => x.IsDeleted == false && x.DonorId == request.DonorId);

                    if (existRecord != null)
                    {
                        existRecord.Name               = request.Name;
                        existRecord.ContactPerson      = request.ContactPerson;
                        existRecord.ContactDesignation = request.ContactDesignation;
                        existRecord.ContactPersonEmail = request.ContactPersonEmail;
                        existRecord.ContactPersonCell  = request.ContactPersonCell;
                        existRecord.ModifiedById       = request.ModifiedById;
                        existRecord.ModifiedDate       = DateTime.UtcNow;
                        _dbContext.SaveChanges();
                        response.data.DonorDetailById = existRecord;
                        response.Message = "Success";
                    }
                }
                response.StatusCode  = StaticResource.successStatusCode;
                response.CommonId.Id = Convert.ToInt32(request.DonorId);
                response.Message     = "Success";
            }
            catch (Exception ex)
            {
                response.StatusCode = StaticResource.failStatusCode;
                response.Message    = StaticResource.SomethingWrong + ex.Message;
            }
            return(response);
        }
示例#5
0
        public async Task <ApiResponse> Handle(EditProjectActivityDetailCommand request, CancellationToken cancellationToken)
        {
            ApiResponse response = new ApiResponse();

            try
            {
                var projectactivityDetail = await _dbContext.ProjectActivityDetail.FirstOrDefaultAsync(x => x.ActivityId == request.ActivityId && x.IsDeleted == false);

                if (projectactivityDetail != null)
                {
                    _mapper.Map(request, projectactivityDetail);

                    projectactivityDetail.ModifiedDate = request.ModifiedDate;
                    projectactivityDetail.ModifiedById = request.ModifiedById;
                    projectactivityDetail.IsDeleted    = false;

                    await _dbContext.SaveChangesAsync();

                    if (request.ProvinceId.Any())
                    {
                        var projectActivityProvinceDetailExist = _dbContext.ProjectActivityProvinceDetail.Where(x => x.ActivityId == request.ActivityId && x.IsDeleted == false);

                        if (projectActivityProvinceDetailExist.Any())
                        {
                            _dbContext.ProjectActivityProvinceDetail.RemoveRange(projectActivityProvinceDetailExist);
                            _dbContext.SaveChanges();
                        }

                        List <ProjectActivityProvinceDetail> activityProvienceList = new List <ProjectActivityProvinceDetail>();


                        var districts = _dbContext.DistrictDetail.Where(x => x.IsDeleted == false && request.ProvinceId.Contains(x.ProvinceID.Value)).ToList();

                        var selectedDistrict = districts.Where(x => request.DistrictID.Contains(x.DistrictID))
                                               .Select(x => new ProjectActivityProvinceDetail
                        {
                            DistrictID = x.DistrictID,
                            ProvinceId = x.ProvinceID.Value
                        }).ToList();
                        var provincesWithNoDistrict = request.ProvinceId.Where(x => !selectedDistrict.Select(y => y.ProvinceId).Contains(x)).ToList();

                        foreach (var item in provincesWithNoDistrict)
                        {
                            ProjectActivityProvinceDetail projectActivityProvince = new ProjectActivityProvinceDetail();
                            projectActivityProvince.ProvinceId = item;
                            selectedDistrict.Add(projectActivityProvince);
                        }

                        foreach (var item in selectedDistrict)
                        {
                            item.ActivityId   = projectactivityDetail.ActivityId;
                            item.ModifiedById = request.ModifiedById;
                            item.ModifiedDate = request.ModifiedDate;
                            item.IsDeleted    = false;
                        }
                        await _dbContext.ProjectActivityProvinceDetail.AddRangeAsync(selectedDistrict);

                        await _dbContext.SaveChangesAsync();
                    }

                    response.StatusCode = StaticResource.successStatusCode;
                    response.Message    = "Success";
                }
                else
                {
                    response.StatusCode = StaticResource.failStatusCode;
                    response.Message    = StaticResource.ActivityNotFound;
                }
            }
            catch (Exception ex)
            {
                response.StatusCode = StaticResource.failStatusCode;
                response.Message    = StaticResource.SomethingWrong + ex.Message;
            }
            return(response);
        }
        /// <summary>
        /// Add/Edit Transaction
        /// </summary>
        /// <param name="request"></param>
        /// <param name="_dbContext"></param>
        /// <returns>true/Exception</returns>
        public bool AddEditTransactionList(AddEditTransactionListCommand request)
        {
            List <VoucherTransactions> transactionsListAdd  = new List <VoucherTransactions>();
            List <VoucherTransactions> transactionsListEdit = new List <VoucherTransactions>();

            try
            {
                if (!request.VoucherTransactions.Any())
                {
                    throw new Exception(StaticResource.NoTransactionToUpDate);
                }

                var editList = request.VoucherTransactions.Where(w => w.TransactionId != 0)
                               .Select(s => s.TransactionId);

                var editTransactionList = _dbContext.VoucherTransactions
                                          .Where(x => editList.Contains(x.TransactionId))
                                          .ToList();

                var voucherDetail = _dbContext.VoucherDetail.FirstOrDefault(x => x.IsDeleted == false && x.VoucherNo == request.VoucherNo);

                if (voucherDetail == null)
                {
                    throw new Exception(StaticResource.VoucherNotPresent);
                }

                foreach (VoucherTransactionsModel item in request.VoucherTransactions)
                {
                    // Add
                    if (item.TransactionId == 0 && item.IsDeleted == false)
                    {
                        //new voucher transaction object
                        VoucherTransactions transaction = new VoucherTransactions();

                        transaction.ChartOfAccountNewId = item.AccountNo;
                        transaction.Debit           = item.Debit;
                        transaction.Credit          = item.Credit;
                        transaction.Description     = item.Description;
                        transaction.BudgetLineId    = item.BudgetLineId;
                        transaction.ProjectId       = item.ProjectId;
                        transaction.CreatedById     = request.ModifiedById;
                        transaction.CreatedDate     = DateTime.UtcNow;
                        transaction.IsDeleted       = false;
                        transaction.VoucherNo       = item.VoucherNo;
                        transaction.CurrencyId      = voucherDetail.CurrencyId;
                        transaction.TransactionDate = voucherDetail.VoucherDate;
                        transaction.JobId           = item.JobId == 0 ? null : item.JobId;

                        transactionsListAdd.Add(transaction);
                    }
                    // edit
                    else
                    {
                        VoucherTransactions transaction = editTransactionList.FirstOrDefault(x => x.TransactionId == item.TransactionId);

                        if (transaction != null)
                        {
                            if (item.IsDeleted == false)
                            {
                                transaction.IsDeleted = false;
                            }
                            else
                            {
                                transaction.IsDeleted = true;
                            }
                            transaction.TransactionId       = item.TransactionId;
                            transaction.ChartOfAccountNewId = item.AccountNo;
                            transaction.Debit           = item.Debit;
                            transaction.Credit          = item.Credit;
                            transaction.Description     = item.Description;
                            transaction.BudgetLineId    = item.BudgetLineId;
                            transaction.ProjectId       = item.ProjectId;
                            transaction.JobId           = item.JobId == 0 ? null : item.JobId;
                            transaction.CurrencyId      = voucherDetail.CurrencyId;
                            transaction.TransactionDate = voucherDetail.VoucherDate;
                            transaction.ModifiedById    = request.ModifiedById;
                            transaction.ModifiedDate    = DateTime.UtcNow;

                            transactionsListEdit.Add(transaction);
                        }
                    }
                }

                using (IDbContextTransaction tran = _dbContext.Database.BeginTransaction())
                {
                    try
                    {
                        _dbContext.VoucherTransactions.AddRange(transactionsListAdd);
                        _dbContext.VoucherTransactions.UpdateRange(transactionsListEdit);

                        _dbContext.SaveChanges();
                        tran.Commit();
                    }

                    catch (Exception ex)
                    {
                        tran.Rollback();

                        throw new Exception(ex.Message);
                    }
                }

                return(true);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        public ApiResponse AddEditTransactionList(AddEditTransactionModel voucherTransactions, string userId)
        {
            ApiResponse response = new ApiResponse();

            List <VoucherTransactions> transactionsListAdd  = new List <VoucherTransactions>();
            List <VoucherTransactions> transactionsListEdit = new List <VoucherTransactions>();

            try
            {
                if (voucherTransactions.VoucherTransactions.Any())
                {
                    var editList = voucherTransactions.VoucherTransactions.Where(w => w.TransactionId != 0)
                                   .Select(s => s.TransactionId);

                    var editTransactionList = _dbContext.VoucherTransactions
                                              .Where(x => editList
                                                     .Contains(x.TransactionId))
                                              .ToList();

                    var voucherDetail = _dbContext.VoucherDetail.FirstOrDefault(x => x.IsDeleted == false && x.VoucherNo == voucherTransactions.VoucherNo);

                    if (voucherDetail != null)
                    {
                        foreach (VoucherTransactionsModel item in voucherTransactions.VoucherTransactions)
                        {
                            // Add
                            if (item.TransactionId == 0 && item.IsDeleted == false)
                            {
                                //new voucher transaction object
                                VoucherTransactions transaction = new VoucherTransactions();

                                transaction.ChartOfAccountNewId = item.AccountNo;
                                transaction.Debit           = item.Debit;
                                transaction.Credit          = item.Credit;
                                transaction.Description     = item.Description;
                                transaction.BudgetLineId    = item.BudgetLineId;
                                transaction.ProjectId       = item.ProjectId;
                                transaction.CreatedById     = userId;
                                transaction.CreatedDate     = DateTime.Now;
                                transaction.IsDeleted       = false;
                                transaction.VoucherNo       = item.VoucherNo;
                                transaction.CurrencyId      = voucherDetail.CurrencyId;
                                transaction.TransactionDate = voucherDetail.VoucherDate;
                                transaction.JobId           = item.JobId == 0 ? null : item.JobId;

                                transactionsListAdd.Add(transaction);
                            }
                            // edit
                            else
                            {
                                VoucherTransactions transaction = editTransactionList.FirstOrDefault(x => x.TransactionId == item.TransactionId);

                                if (transaction != null)
                                {
                                    if (item.IsDeleted == false)
                                    {
                                        transaction.IsDeleted = false;
                                    }
                                    else
                                    {
                                        transaction.IsDeleted = true;
                                    }
                                    transaction.TransactionId       = item.TransactionId;
                                    transaction.ChartOfAccountNewId = item.AccountNo;
                                    transaction.Debit           = item.Debit;
                                    transaction.Credit          = item.Credit;
                                    transaction.Description     = item.Description;
                                    transaction.BudgetLineId    = item.BudgetLineId;
                                    transaction.ProjectId       = item.ProjectId;
                                    transaction.JobId           = item.JobId == 0 ? null : item.JobId;
                                    transaction.CurrencyId      = voucherDetail.CurrencyId;
                                    transaction.TransactionDate = voucherDetail.VoucherDate;
                                    transaction.ModifiedById    = userId;
                                    transaction.ModifiedDate    = DateTime.Now;
                                    //transaction.VoucherNo = voucherTransactions.VoucherNo;

                                    transactionsListEdit.Add(transaction);
                                }
                            }
                        }

                        using (IDbContextTransaction tran = _dbContext.Database.BeginTransaction())
                        {
                            try
                            {
                                _dbContext.VoucherTransactions.AddRange(transactionsListAdd);
                                _dbContext.VoucherTransactions.UpdateRange(transactionsListEdit);

                                _dbContext.SaveChanges();
                                tran.Commit();
                            }

                            catch (Exception ex)
                            {
                                tran.Rollback();
                                response.StatusCode = StaticResource.failStatusCode;
                                response.Message    = StaticResource.SomethingWrong + ex.Message;
                                return(response);
                            }
                        }

                        response.StatusCode = StaticResource.successStatusCode;
                        response.Message    = StaticResource.SuccessText;
                    }
                    else
                    {
                        response.StatusCode = StaticResource.failStatusCode;
                        response.Message    = StaticResource.VoucherNotPresent;
                    }
                }
                else
                {
                    response.StatusCode = StaticResource.failStatusCode;
                    response.Message    = StaticResource.SomethingWrong;
                }
            }
            catch (Exception ex)
            {
                response.StatusCode = StaticResource.failStatusCode;
                response.Message    = StaticResource.SomethingWrong + ex.Message;
            }
            return(response);
        }
        public async Task <ApiResponse> Handle(UpdatePermissionsOnSelectedRoleCommand request, CancellationToken cancellationToken)
        {
            ApiResponse response = new ApiResponse();

            try
            {
                // UpdateRole
                IdentityResult identityResult = new IdentityResult();

                var roleExists = await _roleManager.FindByIdAsync(request.RoleId);

                if (roleExists != null)
                {
                    roleExists.Name = request.RoleName;
                    identityResult  = await _roleManager.UpdateAsync(roleExists);
                }
                if (!identityResult.Succeeded)
                {
                    throw new Exception(StaticResource.SomethingWentWrong);
                }


                // update permission
                if (request != null)
                {
                    //get all permissions that exists for the role
                    List <RolePermissions> rolePermissionsList = await _dbContext.RolePermissions.Where(x => x.IsDeleted == false && x.RoleId == request.RoleId).ToListAsync();

                    List <RolePermissions>         removedPermissions = rolePermissionsList.Where(x => !request.Permissions.Select(y => y.PageId).Contains(x.PageId.Value)).ToList();
                    List <ApproveRejectPermission> approveRejectRolePermissionsList = await _dbContext.ApproveRejectPermission.Where(x => x.IsDeleted == false && x.RoleId == request.RoleId).ToListAsync();

                    List <AgreeDisagreePermission> agreeDisagreeRolePermissionsList = await _dbContext.AgreeDisagreePermission.Where(x => x.IsDeleted == false && x.RoleId == request.RoleId).ToListAsync();

                    List <OrderSchedulePermission> orderScheduleRolePermissionsList = await _dbContext.OrderSchedulePermission.Where(x => x.IsDeleted == false && x.RoleId == request.RoleId).ToListAsync();

                    List <ApproveRejectPermission> approveRejectRemovePermissions = approveRejectRolePermissionsList.Where(x => !request.Permissions.Select(y => y.PageId).Contains(x.PageId)).ToList();
                    List <AgreeDisagreePermission> agreeDisagreeRemovePermissions = agreeDisagreeRolePermissionsList.Where(x => !request.Permissions.Select(y => y.PageId).Contains(x.PageId)).ToList();
                    List <OrderSchedulePermission> orderScheduleRemovePermissions = orderScheduleRolePermissionsList.Where(x => !request.Permissions.Select(y => y.PageId).Contains(x.PageId)).ToList();
                    removedPermissions.ForEach(x => x.IsDeleted             = true);
                    approveRejectRemovePermissions.ForEach(x => x.IsDeleted = true);
                    agreeDisagreeRemovePermissions.ForEach(x => x.IsDeleted = true);
                    orderScheduleRemovePermissions.ForEach(x => x.IsDeleted = true);
                    _dbContext.RolePermissions.UpdateRange(removedPermissions);
                    _dbContext.ApproveRejectPermission.UpdateRange(approveRejectRemovePermissions);
                    _dbContext.AgreeDisagreePermission.UpdateRange(agreeDisagreeRemovePermissions);
                    _dbContext.OrderSchedulePermission.UpdateRange(orderScheduleRemovePermissions);
                    _dbContext.SaveChanges();

                    foreach (ApplicationPagesModel item in request.Permissions)
                    {
                        if (item.View == true || item.Edit == true)
                        {
                            //get the previous permission set for the pageId if exists
                            RolePermissions rolePermissions = rolePermissionsList.FirstOrDefault(x => x.PageId == item.PageId);

                            //If permission for the page does not exist then initialize object
                            rolePermissions = rolePermissions ?? new RolePermissions();

                            rolePermissions.CanEdit     = item.Edit;
                            rolePermissions.CanView     = item.View;
                            rolePermissions.CreatedDate = rolePermissions.CreatedDate ?? DateTime.Now;
                            rolePermissions.IsDeleted   = false;
                            rolePermissions.PageId      = item.PageId;
                            rolePermissions.RoleId      = request.RoleId;
                            rolePermissions.ModuleId    = item.ModuleId;

                            //save a new entry in the rolepermissions table
                            if (rolePermissions.RolesPermissionId == 0)
                            {
                                _dbContext.RolePermissions.Add(rolePermissions);
                                _dbContext.SaveChanges();
                                _dbContext.Entry <RolePermissions>(rolePermissions).State = EntityState.Detached;
                            }
                            else//update existing permissions record for the page
                            {
                                rolePermissions.ModifiedDate = DateTime.Now;
                                _dbContext.RolePermissions.Update(rolePermissions);
                                _dbContext.SaveChanges();
                                _dbContext.Entry <RolePermissions>(rolePermissions).State = EntityState.Detached;
                            }
                        }
                        if (item.Approve == true || item.Reject == true)
                        {
                            ApproveRejectPermission approveRejectRolePermissions = approveRejectRolePermissionsList.FirstOrDefault(x => x.PageId == item.PageId);

                            //If permission for the page does not exist then initialize object
                            approveRejectRolePermissions             = approveRejectRolePermissions ?? new ApproveRejectPermission();
                            approveRejectRolePermissions.Approve     = item.Approve;
                            approveRejectRolePermissions.Reject      = item.Reject;
                            approveRejectRolePermissions.CreatedDate = approveRejectRolePermissions.CreatedDate ?? DateTime.UtcNow;
                            approveRejectRolePermissions.IsDeleted   = false;
                            approveRejectRolePermissions.PageId      = item.PageId;
                            approveRejectRolePermissions.RoleId      = request.RoleId;

                            //save a new entry in the rolepermissions table
                            if (approveRejectRolePermissions.Id == 0)
                            {
                                _dbContext.ApproveRejectPermission.Add(approveRejectRolePermissions);
                                _dbContext.SaveChanges();
                                _dbContext.Entry <ApproveRejectPermission>(approveRejectRolePermissions).State = EntityState.Detached;
                            }
                            else//update existing permissions record for the page
                            {
                                approveRejectRolePermissions.ModifiedDate = DateTime.Now;
                                _dbContext.ApproveRejectPermission.Update(approveRejectRolePermissions);
                                _dbContext.SaveChanges();
                                _dbContext.Entry <ApproveRejectPermission>(approveRejectRolePermissions).State = EntityState.Detached;
                            }
                        }
                        if (item.Agree == true || item.Disagree == true)
                        {
                            AgreeDisagreePermission agreeDisagreeRolePermissions = agreeDisagreeRolePermissionsList.FirstOrDefault(x => x.PageId == item.PageId);

                            //If permission for the page does not exist then initialize object
                            agreeDisagreeRolePermissions             = agreeDisagreeRolePermissions ?? new AgreeDisagreePermission();
                            agreeDisagreeRolePermissions.Agree       = item.Agree;
                            agreeDisagreeRolePermissions.Disagree    = item.Disagree;
                            agreeDisagreeRolePermissions.CreatedDate = agreeDisagreeRolePermissions.CreatedDate ?? DateTime.UtcNow;
                            agreeDisagreeRolePermissions.IsDeleted   = false;
                            agreeDisagreeRolePermissions.PageId      = item.PageId;
                            agreeDisagreeRolePermissions.RoleId      = request.RoleId;

                            //save a new entry in the rolepermissions table
                            if (agreeDisagreeRolePermissions.Id == 0)
                            {
                                _dbContext.AgreeDisagreePermission.Add(agreeDisagreeRolePermissions);
                                _dbContext.SaveChanges();
                                _dbContext.Entry <AgreeDisagreePermission>(agreeDisagreeRolePermissions).State = EntityState.Detached;
                            }
                            else//update existing permissions record for the page
                            {
                                agreeDisagreeRolePermissions.ModifiedDate = DateTime.Now;
                                _dbContext.AgreeDisagreePermission.Update(agreeDisagreeRolePermissions);
                                _dbContext.SaveChanges();
                                _dbContext.Entry <AgreeDisagreePermission>(agreeDisagreeRolePermissions).State = EntityState.Detached;
                            }
                        }
                        OrderSchedulePermission orderScheduleRolePermissions = orderScheduleRolePermissionsList.FirstOrDefault(x => x.PageId == item.PageId);

                        //If permission for the page does not exist then initialize object
                        orderScheduleRolePermissions = orderScheduleRolePermissions ?? new OrderSchedulePermission();
                        orderScheduleRolePermissions.OrderSchedule = item.OrderSchedule;
                        orderScheduleRolePermissions.CreatedDate   = orderScheduleRolePermissions.CreatedDate ?? DateTime.UtcNow;
                        orderScheduleRolePermissions.IsDeleted     = false;
                        orderScheduleRolePermissions.PageId        = item.PageId;
                        orderScheduleRolePermissions.RoleId        = request.RoleId;

                        //save a new entry in the rolepermissions table
                        if (orderScheduleRolePermissions.Id == 0)
                        {
                            _dbContext.OrderSchedulePermission.Add(orderScheduleRolePermissions);
                            _dbContext.SaveChanges();
                            _dbContext.Entry <OrderSchedulePermission>(orderScheduleRolePermissions).State = EntityState.Detached;
                        }
                        else//update existing permissions record for the page
                        {
                            orderScheduleRolePermissions.ModifiedDate = DateTime.Now;
                            _dbContext.OrderSchedulePermission.Update(orderScheduleRolePermissions);
                            _dbContext.SaveChanges();
                            _dbContext.Entry <OrderSchedulePermission>(orderScheduleRolePermissions).State = EntityState.Detached;
                        }
                    }

                    response.StatusCode = StaticResource.successStatusCode;
                    response.Message    = StaticResource.SuccessText;
                }
                else
                {
                    response.StatusCode = StaticResource.failStatusCode;
                    response.Message    = StaticResource.NoDataFound;
                }
            }
            catch (Exception ex)
            {
                response.StatusCode = StaticResource.failStatusCode;
                response.Message    = ex.Message;
            }
            return(response);
        }
        public async Task <ApiResponse> Handle(AddEditProvinceByProjectIdCommand request, CancellationToken cancellationToken)
        {
            ApiResponse response = new ApiResponse();

            try
            {
                if (request.ProvinceId.Count != 0)
                {
                    var provinceExist = await _dbContext.ProvinceMultiSelect.Where(x => x.ProjectId == request.ProjectId && x.IsDeleted == false).ToListAsync();

                    var noExistProvinceId = provinceExist.Where(x => !request.ProvinceId.Contains(x.ProvinceId)).Select(x => x.ProvinceId).ToList();

                    if (provinceExist.Any())
                    {
                        var districtExist = await _dbContext.DistrictMultiSelect.Where(x => noExistProvinceId.Contains(x.ProvinceId) && x.IsDeleted == false).ToListAsync();

                        if (districtExist.Any())
                        {
                            _dbContext.DistrictMultiSelect.RemoveRange(districtExist);
                            await _dbContext.SaveChangesAsync();
                        }
                        _dbContext.ProvinceMultiSelect.RemoveRange(provinceExist);
                        _dbContext.SaveChanges();
                    }
                }
                else
                {
                    var districtExist = _dbContext.DistrictMultiSelect.Where(x => x.IsDeleted == false).ToList();
                    if (districtExist.Any())
                    {
                        _dbContext.DistrictMultiSelect.RemoveRange(districtExist);
                        await _dbContext.SaveChangesAsync();
                    }
                }

                List <ProvinceMultiSelect> provinceList = new List <ProvinceMultiSelect>();

                foreach (var item in request.ProvinceId)
                {
                    ProvinceMultiSelect _data = new ProvinceMultiSelect();

                    _data.ProvinceId  = item;
                    _data.ProjectId   = request.ProjectId;
                    _data.IsDeleted   = false;
                    _data.CreatedById = request.CreatedById;
                    _data.CreatedDate = DateTime.UtcNow;

                    provinceList.Add(_data);
                    await _dbContext.SaveChangesAsync();
                }
                //Add
                _dbContext.ProvinceMultiSelect.AddRange(provinceList);
                await _dbContext.SaveChangesAsync();

                response.StatusCode = StaticResource.successStatusCode;
                response.Message    = "Success";
            }
            catch (Exception ex)
            {
                response.StatusCode = StaticResource.failStatusCode;
                response.Message    = StaticResource.SomethingWrong + ex.Message;
            }

            return(response);
        }
示例#10
0
        public async Task <ApiResponse> Handle(AddEditProjectDetailCommand request, CancellationToken cancellationToken)
        {
            ApiResponse      response        = new ApiResponse();
            ProjectPhaseTime _ProjectPhase   = new ProjectPhaseTime();
            ProjectDetail    _ProjectDetail  = new ProjectDetail();
            DbContext        db              = _dbContext;
            long             LatestprojectId = 0;
            var projectcode = string.Empty;

            using (IDbContextTransaction tran = db.Database.BeginTransaction())
            {
                try
                {
                    if (request.ProjectId == 0)
                    {
                        var ProjectDetail = _dbContext.ProjectDetail
                                            .OrderByDescending(x => x.ProjectId)
                                            .FirstOrDefault(x => x.IsDeleted == false);
                        if (ProjectDetail == null)
                        {
                            LatestprojectId = 1;
                            projectcode     = ProjectUtility.GenerateProjectCode(LatestprojectId);
                        }
                        else
                        {
                            LatestprojectId = ProjectDetail.ProjectId + 1;
                            projectcode     = ProjectUtility.GenerateProjectCode(LatestprojectId);
                        }

                        ProjectDetail obj = _mapper.Map <AddEditProjectDetailCommand, ProjectDetail>(request);
                        obj.ProjectCode = projectcode; // ProjectDetail != null ? getProjectCode(ProjectDetail.ProjectId.ToString()) : getProjectCode("1");

                        obj.ProjectName           = request.ProjectName;
                        obj.ProjectDescription    = request.ProjectDescription;
                        obj.StartDate             = DateTime.UtcNow;
                        obj.EndDate               = request.EndDate;
                        obj.IsProposalComplate    = request.IsProposalComplate;
                        obj.ReviewerId            = request.ReviewerId;
                        obj.DirectorId            = request.DirectorId;
                        obj.ProjectPhaseDetailsId = (int)ProjectPhaseType.Planning;
                        obj.IsDeleted             = false;
                        obj.IsActive              = true;
                        obj.CreatedById           = request.CreatedById;
                        obj.CreatedDate           = DateTime.UtcNow;
                        _dbContext.ProjectDetail.Add(obj);
                        _dbContext.SaveChanges();
                        _ProjectPhase.ProjectId             = LatestprojectId = obj.ProjectId;
                        _ProjectPhase.ProjectPhaseDetailsId = (int)ProjectPhaseType.Planning;
                        _ProjectPhase.PhaseStartData        = DateTime.UtcNow;
                        _ProjectPhase.IsDeleted             = false;
                        _ProjectPhase.CreatedById           = request.CreatedById;
                        _ProjectPhase.CreatedDate           = DateTime.UtcNow;
                        _dbContext.ProjectPhaseTime.Add(_ProjectPhase);
                        _dbContext.SaveChanges();

                        response.data.ProjectDetail = obj; //don't remove this
                    }
                    else
                    {
                        ProjectDetail    existProjectRecord      = _dbContext.ProjectDetail.FirstOrDefault(x => x.IsDeleted == false && x.ProjectId == request.ProjectId);
                        ProjectPhaseTime exstingProjectTimePhase = _dbContext.ProjectPhaseTime.FirstOrDefault(y => y.IsDeleted == false && y.ProjectId == request.ProjectId);
                        if (existProjectRecord != null)
                        {
                            existProjectRecord.ProjectName        = request.ProjectName;
                            existProjectRecord.ProjectDescription = request.ProjectDescription;
                            existProjectRecord.IsProposalComplate = request.IsProposalComplate;
                            existProjectRecord.ReviewerId         = request.ReviewerId;
                            existProjectRecord.DirectorId         = request.DirectorId;
                            existProjectRecord.IsDeleted          = false;
                            existProjectRecord.ModifiedById       = request.ModifiedById;
                            existProjectRecord.ModifiedDate       = DateTime.UtcNow;
                            _dbContext.SaveChanges();
                            if (exstingProjectTimePhase != null)
                            {
                                _ProjectPhase.ProjectPhaseDetailsId = (int)ProjectPhaseType.Planning;
                                _ProjectPhase.PhaseStartData        = DateTime.UtcNow;
                                _ProjectPhase.IsDeleted             = false;
                                _ProjectPhase.ModifiedById          = request.ModifiedById;
                                _ProjectPhase.ModifiedDate          = DateTime.UtcNow;
                                _dbContext.SaveChanges();
                            }
                            //_uow.GetDbContext().SaveChanges();
                            LatestprojectId = request.ProjectId;
                        }
                    }
                    response.StatusCode  = StaticResource.successStatusCode;
                    response.CommonId.Id = Convert.ToInt32(LatestprojectId);

                    response.Message = "Success";
                    tran.Commit();
                }
                catch (Exception ex)
                {
                    tran.Rollback();
                    response.StatusCode = StaticResource.failStatusCode;
                    response.Message    = StaticResource.SomethingWrong + ex.Message;
                }
            }
            return(response);
        }