Пример #1
0
        public async Task <bool> AddUpdateCashierTellerSetupAsync(deposit_cashiertellersetup model)
        {
            try
            {
                if (model.DepositCashierTellerSetupId > 0)
                {
                    var itemToUpdate = await _dataContext.deposit_cashiertellersetup.FindAsync(model.DepositCashierTellerSetupId);

                    _dataContext.Entry(itemToUpdate).CurrentValues.SetValues(model);
                }
                else
                {
                    await _dataContext.deposit_cashiertellersetup.AddAsync(model);
                }
                return(await _dataContext.SaveChangesAsync() > 0);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #2
0
        public async Task <ActionResult <CashierTellerSetupRegRespObj> > AddUpDateCashierTellerSetup([FromBody] AddUpdateCashierTellerSetupObj model)
        {
            try
            {
                var user = await _serverRequest.UserDataAsync();

                deposit_cashiertellersetup item = null;
                if (model.DepositCashierTellerSetupId > 0)
                {
                    item = await _repo.GetCashierTellerSetupByIdAsync(model.DepositCashierTellerSetupId);

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

                var domainObj = new deposit_cashiertellersetup();

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


                var isDone = await _repo.AddUpdateCashierTellerSetupAsync(domainObj);

                return(new CashierTellerSetupRegRespObj
                {
                    DepositCashierTellerSetupId = domainObj.DepositCashierTellerSetupId,
                    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 CashierTellerSetupRegRespObj
                {
                    Status = new APIResponseStatus {
                        IsSuccessful = false, Message = new APIResponseMessage {
                            FriendlyMessage = "Error Occurred", TechnicalMessage = ex?.Message, MessageId = errorCode
                        }
                    }
                });
            }
        }
Пример #3
0
        public async Task <bool> UploadCashierTellerSetupAsync(byte[] record, string createdBy)
        {
            try
            {
                if (record == null)
                {
                    return(false);
                }
                List <deposit_cashiertellersetup> uploadedRecord = new List <deposit_cashiertellersetup>();
                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_cashiertellersetup
                            {
                                Structure   = workSheet.Cells[i, 1].Value != null ? int.Parse(workSheet.Cells[i, 1].Value.ToString()) : 0,
                                ProductId   = workSheet.Cells[i, 2].Value != null ? int.Parse(workSheet.Cells[i, 2].Value.ToString()) : 0,
                                PresetChart = workSheet.Cells[i, 3].Value != null ? bool.Parse(workSheet.Cells[i, 3].Value.ToString()) : false,
                            });
                        }
                    }
                if (uploadedRecord.Count > 0)
                {
                    foreach (var item in uploadedRecord)
                    {
                        var category = _dataContext.deposit_cashiertellersetup.Where(x => x.PresetChart == item.PresetChart && x.Deleted == false).FirstOrDefault();
                        if (category != null)
                        {
                            category.Structure   = item.Structure;
                            category.ProductId   = item.ProductId;
                            category.PresetChart = item.PresetChart;
                            category.Active      = true;
                            category.Deleted     = false;
                            category.UpdatedBy   = createdBy;
                            category.UpdatedOn   = DateTime.Now;
                        }
                        else
                        {
                            var structure = new deposit_cashiertellersetup
                            {
                                Structure   = item.Structure,
                                ProductId   = item.ProductId,
                                PresetChart = item.PresetChart,
                                Active      = true,
                                Deleted     = false,
                                CreatedBy   = createdBy,
                                CreatedOn   = DateTime.Now,
                            };
                            await _dataContext.deposit_cashiertellersetup.AddAsync(structure);
                        }
                    }
                }

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