コード例 #1
0
        public async Task <bool> AddUpdateTransactionChargeAsync(deposit_transactioncharge model)
        {
            try
            {
                if (model.TransactionChargeId > 0)
                {
                    var itemToUpdate = await _dataContext.deposit_transactioncharge.FindAsync(model.TransactionChargeId);

                    _dataContext.Entry(itemToUpdate).CurrentValues.SetValues(model);
                }
                else
                {
                    await _dataContext.deposit_transactioncharge.AddAsync(model);
                }
                return(await _dataContext.SaveChangesAsync() > 0);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #2
0
        public async Task <ActionResult <TransactionChargeRegRespObj> > AddUpDateTransactionCharge([FromBody] AddUpdateTransactionChargeObj model)
        {
            try
            {
                var user = await _serverRequest.UserDataAsync();

                deposit_transactioncharge item = null;
                if (model.TransactionChargeId > 0)
                {
                    item = await _repo.GetTransactionChargeByIdAsync(model.TransactionChargeId);

                    if (item == null)
                    {
                        return new TransactionChargeRegRespObj
                               {
                                   Status = new APIResponseStatus {
                                       IsSuccessful = false, Message = new APIResponseMessage {
                                           FriendlyMessage = "Item does not Exist"
                                       }
                                   }
                               }
                    }
                    ;
                }

                var domainObj = new deposit_transactioncharge();

                domainObj.TransactionChargeId = model.TransactionChargeId > 0 ? model.TransactionChargeId : 0;
                domainObj.Active            = true;
                domainObj.CreatedBy         = user.UserName;
                domainObj.CreatedOn         = DateTime.Today;
                domainObj.Deleted           = false;
                domainObj.Description       = model.Description;
                domainObj.FixedOrPercentage = model.FixedOrPercentage;
                domainObj.Amount_Percentage = model.Amount_Percentage;
                domainObj.Name      = model.Name;
                domainObj.UpdatedBy = user.UserName;
                domainObj.UpdatedOn = model.TransactionChargeId > 0 ? DateTime.Today : DateTime.Today;


                var isDone = await _repo.AddUpdateTransactionChargeAsync(domainObj);

                return(new TransactionChargeRegRespObj
                {
                    TransactionChargeId = domainObj.TransactionChargeId,
                    Status = new APIResponseStatus {
                        IsSuccessful = isDone ? true : false, Message = new APIResponseMessage {
                            FriendlyMessage = isDone ? "successful" : "Unsuccessful"
                        }
                    }
                });
            }
            catch (Exception ex)
            {
                var errorCode = ErrorID.Generate(5);
                _logger.Error($"ErrorID : {errorCode} Ex : {ex?.Message ?? ex?.InnerException?.Message} ErrorStack : {ex?.StackTrace}");
                return(new TransactionChargeRegRespObj
                {
                    Status = new APIResponseStatus {
                        IsSuccessful = false, Message = new APIResponseMessage {
                            FriendlyMessage = "Error Occurred", TechnicalMessage = ex?.Message, MessageId = errorCode
                        }
                    }
                });
            }
        }
コード例 #3
0
        public async Task <bool> UploadTransactionChargeAsync(byte[] record, string createdBy)
        {
            try
            {
                if (record == null)
                {
                    return(false);
                }
                List <deposit_transactioncharge> uploadedRecord = new List <deposit_transactioncharge>();
                using (MemoryStream stream = new MemoryStream(record))
                    using (ExcelPackage excelPackage = new ExcelPackage(stream))
                    {
                        //Use first sheet by default
                        ExcelWorksheet workSheet = excelPackage.Workbook.Worksheets[1];
                        int            totalRows = workSheet.Dimension.Rows;
                        //First row is considered as the header
                        for (int i = 2; i <= totalRows; i++)
                        {
                            uploadedRecord.Add(new deposit_transactioncharge
                            {
                                Name = workSheet.Cells[i, 1].Value != null ? workSheet.Cells[i, 1].Value.ToString() : null,
                                FixedOrPercentage = workSheet.Cells[i, 2].Value != null ? workSheet.Cells[i, 2].Value.ToString() : null,
                                Amount_Percentage = workSheet.Cells[i, 3].Value != null ? decimal.Parse(workSheet.Cells[i, 3].Value.ToString()) : 0,
                                Description       = workSheet.Cells[i, 4].Value != null ? workSheet.Cells[i, 2].Value.ToString() : null,
                            });
                        }
                    }
                if (uploadedRecord.Count > 0)
                {
                    foreach (var item in uploadedRecord)
                    {
                        var charge = _dataContext.deposit_transactioncharge.Where(x => x.Name == item.Name && x.Deleted == false).FirstOrDefault();
                        if (charge != null)
                        {
                            charge.Name = item.Name;
                            charge.FixedOrPercentage = item.FixedOrPercentage;
                            charge.Amount_Percentage = item.Amount_Percentage;
                            charge.Description       = item.Description;
                            charge.Active            = true;
                            charge.Deleted           = false;
                            charge.UpdatedBy         = createdBy;
                            charge.UpdatedOn         = DateTime.Now;
                        }
                        else
                        {
                            var structure = new deposit_transactioncharge
                            {
                                Name = item.Name,
                                FixedOrPercentage = item.FixedOrPercentage,
                                Amount_Percentage = item.Amount_Percentage,
                                Description       = item.Description,
                                Active            = true,
                                Deleted           = false,
                                CreatedBy         = createdBy,
                                CreatedOn         = DateTime.Now,
                            };
                            await _dataContext.deposit_transactioncharge.AddAsync(structure);
                        }
                    }
                }

                var response = _dataContext.SaveChanges() > 0;
                return(response);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }