Beispiel #1
0
        public async Task <bool> AddUpdateChangeOfRatesSetupAsync(deposit_changeofratesetup model)
        {
            try
            {
                if (model.ChangeOfRateSetupId > 0)
                {
                    var itemToUpdate = await _dataContext.deposit_changeofratesetup.FindAsync(model.ChangeOfRateSetupId);

                    _dataContext.Entry(itemToUpdate).CurrentValues.SetValues(model);
                }
                else
                {
                    await _dataContext.deposit_changeofratesetup.AddAsync(model);
                }
                return(await _dataContext.SaveChangesAsync() > 0);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #2
0
        public async Task <bool> UploadChangeOfRatesSetupAsync(List <byte[]> record, string createdBy)
        {
            try
            {
                if (record == null)
                {
                    return(false);
                }
                ExcelPackage.LicenseContext = LicenseContext.NonCommercial;
                List <deposit_changeofratesetup> uploadedRecord = new List <deposit_changeofratesetup>();
                if (record.Count() > 0)
                {
                    foreach (var byteItem in record)
                    {
                        using (MemoryStream stream = new MemoryStream(byteItem))
                            using (ExcelPackage excelPackage = new ExcelPackage(stream))
                            {
                                ExcelWorksheet workSheet = excelPackage.Workbook.Worksheets[0];
                                int            totalRows = workSheet.Dimension.Rows;

                                for (int i = 2; i <= totalRows; i++)
                                {
                                    var item = new deposit_changeofratesetup
                                    {
                                        //can = workSheet.Cells[i, 1].Value.ToString(),
                                        //CanApply = workSheet.Cells[i, 2].Value.ToString()
                                    };
                                    uploadedRecord.Add(item);
                                }
                            }
                    }
                }
                if (uploadedRecord.Count > 0)
                {
                    foreach (var item in uploadedRecord)
                    {
                        var ChangeOfRatesexist = _dataContext.deposit_changeofratesetup.Where(x => x.ChangeOfRateSetupId == item.ChangeOfRateSetupId && x.Deleted == false).FirstOrDefault();
                        if (ChangeOfRatesexist != null)
                        {
                            ChangeOfRatesexist.CanApply = item.CanApply;
                            //ChangeOfRatesexist.can = item.CanApply;
                            ChangeOfRatesexist.Active    = true;
                            ChangeOfRatesexist.Deleted   = false;
                            ChangeOfRatesexist.UpdatedBy = item.UpdatedBy;
                            ChangeOfRatesexist.UpdatedOn = DateTime.Now;
                        }

                        else
                        {
                            var ChangeOfRates = new deposit_changeofratesetup
                            {
                                CanApply = item.CanApply,
                                //Description = item.Description,
                                Active    = true,
                                Deleted   = false,
                                CreatedBy = createdBy,
                                CreatedOn = DateTime.Now,
                            };
                            await _dataContext.deposit_changeofratesetup.AddAsync(ChangeOfRates);
                        }
                    }
                }

                var response = _dataContext.SaveChanges() > 0;
                return(response);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Beispiel #3
0
        public async Task <ActionResult <ChangeOfRateSetupRegRespObj> > AddUpdateChangeOfRatesSetupAsync([FromBody] AddUpdateChangeOfRateSetupObj model)
        {
            try
            {
                var user = await _identityServer.UserDataAsync();

                deposit_changeofratesetup item = null;
                if (model.ChangeOfRateSetupId > 0)
                {
                    item = await _repo.GetChangeOfRatesSetupByIdAsync(model.ChangeOfRateSetupId);

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

                var domainObj = new deposit_changeofratesetup();

                domainObj.ChangeOfRateSetupId = model.ChangeOfRateSetupId > 0 ? model.ChangeOfRateSetupId : 0;
                domainObj.Structure           = model.Structure;
                domainObj.ProductId           = model.ProductId;
                domainObj.CanApply            = model.CanApply;
                domainObj.Active    = true;
                domainObj.CreatedOn = DateTime.Today;
                domainObj.CreatedBy = user.UserName;
                domainObj.Deleted   = false;
                domainObj.UpdatedOn = model.ChangeOfRateSetupId > 0 ? DateTime.Today : DateTime.Today;
                domainObj.UpdatedBy = user.UserName;

                var isDone = await _repo.AddUpdateChangeOfRatesSetupAsync(domainObj);

                return(new ChangeOfRateSetupRegRespObj
                {
                    ChangeOfRateSetupId = domainObj.ChangeOfRateSetupId,
                    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 ChangeOfRateSetupRegRespObj
                {
                    Status = new APIResponseStatus {
                        IsSuccessful = false, Message = new APIResponseMessage {
                            FriendlyMessage = "Error Occurred", TechnicalMessage = ex?.Message, MessageId = errorCode
                        }
                    }
                });
            }
        }