示例#1
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);
        }
示例#2
0
        public async Task <ApiResponse> Handle(AddPayrollMonthlyHourCommand request, CancellationToken cancellationToken)
        {
            ApiResponse response = new ApiResponse();

            try
            {
                TimeSpan hours;
                hours         = Convert.ToDateTime(request.OutTime) - Convert.ToDateTime(request.InTime);
                request.Hours = Convert.ToInt32(hours.ToString().Substring(0, 2));

                if (request.SaveForAllOffice)
                {
                    List <PayrollMonthlyHourDetail> payrollMonthlyHourDetailsAdd    = new List <PayrollMonthlyHourDetail>();
                    List <PayrollMonthlyHourDetail> payrollMonthlyHourDetailsUpdate = new List <PayrollMonthlyHourDetail>();

                    List <int> officeIds = _dbContext.OfficeDetail.Where(x => x.IsDeleted == false).Select(x => x.OfficeId).ToList();

                    foreach (int officeId in officeIds)
                    {
                        var payrollinfo = await _dbContext.PayrollMonthlyHourDetail
                                          .FirstOrDefaultAsync(x => x.IsDeleted == false &&
                                                               x.OfficeId == officeId &&
                                                               x.PayrollMonth == request.PayrollMonth &&
                                                               x.PayrollYear == request.PayrollYear &&
                                                               x.AttendanceGroupId == request.AttendanceGroupId);

                        if (payrollinfo == null)
                        {
                            PayrollMonthlyHourDetail obj = new PayrollMonthlyHourDetail();
                            obj.CreatedById       = request.CreatedById;
                            obj.CreatedDate       = request.CreatedDate;
                            obj.Hours             = request.Hours;
                            obj.WorkingTime       = request.WorkingTime; //total working hours
                            obj.InTime            = request.InTime;
                            obj.OutTime           = request.OutTime;
                            obj.PayrollMonth      = request.PayrollMonth;
                            obj.PayrollYear       = request.PayrollYear;
                            obj.IsDeleted         = false;
                            obj.OfficeId          = officeId;
                            obj.AttendanceGroupId = request.AttendanceGroupId;
                            payrollMonthlyHourDetailsAdd.Add(obj);
                        }
                        else
                        {
                            payrollinfo.ModifiedDate      = DateTime.UtcNow;
                            payrollinfo.Hours             = request.Hours;
                            payrollinfo.WorkingTime       = request.WorkingTime;
                            payrollinfo.InTime            = request.InTime;
                            payrollinfo.OutTime           = request.OutTime;
                            payrollinfo.PayrollMonth      = request.PayrollMonth;
                            payrollinfo.PayrollYear       = request.PayrollYear;
                            payrollinfo.OfficeId          = officeId;
                            payrollinfo.AttendanceGroupId = request.AttendanceGroupId;
                            payrollMonthlyHourDetailsUpdate.Add(payrollinfo);
                        }
                    }

                    if (payrollMonthlyHourDetailsAdd.Any())
                    {
                        await _dbContext.AddRangeAsync(payrollMonthlyHourDetailsAdd);

                        await _dbContext.SaveChangesAsync();
                    }

                    if (payrollMonthlyHourDetailsUpdate.Any())
                    {
                        _dbContext.UpdateRange(payrollMonthlyHourDetailsUpdate);
                        await _dbContext.SaveChangesAsync();
                    }
                }
                else
                {
                    var payrollinfo = await _dbContext.PayrollMonthlyHourDetail
                                      .FirstOrDefaultAsync(x => x.IsDeleted == false &&
                                                           x.OfficeId == request.OfficeId &&
                                                           x.PayrollMonth == request.PayrollMonth &&
                                                           x.PayrollYear == request.PayrollYear &&
                                                           x.AttendanceGroupId == request.AttendanceGroupId
                                                           );

                    if (payrollinfo == null)
                    {
                        PayrollMonthlyHourDetail obj = new PayrollMonthlyHourDetail();
                        obj.CreatedById       = request.CreatedById;
                        obj.CreatedDate       = request.CreatedDate;
                        obj.Hours             = request.Hours;
                        obj.WorkingTime       = request.WorkingTime; //total working hours
                        obj.InTime            = request.InTime;
                        obj.OutTime           = request.OutTime;
                        obj.PayrollMonth      = request.PayrollMonth;
                        obj.PayrollYear       = request.PayrollYear;
                        obj.IsDeleted         = false;
                        obj.OfficeId          = request.OfficeId;
                        obj.AttendanceGroupId = request.AttendanceGroupId;
                        await _dbContext.PayrollMonthlyHourDetail.AddAsync(obj);

                        await _dbContext.SaveChangesAsync();
                    }
                    else
                    {
                        response.StatusCode = StaticResource.MandateNameAlreadyExistCode;
                        response.Message    = StaticResource.HoursAlreadySet;
                    }
                }

                response.StatusCode = StaticResource.successStatusCode;
                response.Message    = "Success";
            }
            catch (Exception ex)
            {
                response.StatusCode = StaticResource.failStatusCode;
                response.Message    = ex.Message;
            }
            return(response);
        }
示例#3
0
        public async Task <ApiResponse> Handle(SaveGainLossAccountListCommand request, CancellationToken cancellationToken)
        {
            ApiResponse response = new ApiResponse();

            try
            {
                if (request.AccountIds.Any())
                {
                    //Get all Accounts that are already saved
                    List <GainLossSelectedAccounts> gainLossSelectedAccountsList = await _dbContext.GainLossSelectedAccounts.Where(x => x.IsDeleted == false).ToListAsync();

                    if (gainLossSelectedAccountsList.Any())
                    {
                        //Get List of Removed Accounts
                        List <GainLossSelectedAccounts> removedGainLossSelectedAccounts = gainLossSelectedAccountsList.Where(x => !request.AccountIds.Contains(x.ChartOfAccountNewId)).ToList();

                        if (removedGainLossSelectedAccounts.Any())
                        {
                            removedGainLossSelectedAccounts.ForEach(x => x.IsDeleted = true);

                            //Delete and update the table with the accounts already deleted
                            _dbContext.UpdateRange(removedGainLossSelectedAccounts);
                            await _dbContext.SaveChangesAsync();
                        }

                        //Get List of Accounts that are to be added
                        List <long> addGainLossSelectedAccounts = request.AccountIds.Where(x => !gainLossSelectedAccountsList.Select(y => y.ChartOfAccountNewId).Contains(x)).ToList();

                        gainLossSelectedAccountsList = new List <GainLossSelectedAccounts>();

                        foreach (long accountId in addGainLossSelectedAccounts)
                        {
                            GainLossSelectedAccounts gainLossSelectedAccounts = new GainLossSelectedAccounts
                            {
                                IsDeleted           = false,
                                CreatedDate         = DateTime.Now,
                                ChartOfAccountNewId = accountId,
                            };

                            gainLossSelectedAccountsList.Add(gainLossSelectedAccounts);
                        }
                    }
                    else //table is empty so it is safe to save all the accounts
                    {
                        gainLossSelectedAccountsList = new List <GainLossSelectedAccounts>();

                        foreach (long accountId in request.AccountIds)
                        {
                            GainLossSelectedAccounts gainLossSelectedAccounts = new GainLossSelectedAccounts
                            {
                                IsDeleted           = false,
                                CreatedDate         = DateTime.Now,
                                ChartOfAccountNewId = accountId,
                            };

                            gainLossSelectedAccountsList.Add(gainLossSelectedAccounts);
                        }
                    }

                    //Save Accounts to the DB
                    if (gainLossSelectedAccountsList.Any())
                    {
                        await _dbContext.GainLossSelectedAccounts.AddRangeAsync(gainLossSelectedAccountsList);

                        await _dbContext.SaveChangesAsync();
                    }

                    response.StatusCode = StaticResource.successStatusCode;
                    response.Message    = "success";
                }
                else
                {
                    throw new Exception("No Account Selected");
                }
            }
            catch (Exception exception)
            {
                response.StatusCode = StaticResource.failStatusCode;
                response.Message    = exception.Message;
            }

            return(response);
        }