Beispiel #1
0
        /*
         * Developer: Sajid Khan
         * Date: 7-5-19
         * Action: Insert purchase order Ledger data to database
         * Input: new Purchase Orders Ledger data
         * output: string of PurchaseOrders Ledger id
         */
        public async Task <string> Create(PurchaseOrderLedger NewPurchaseOrder)
        {
            using (IDbConnection conn = Connection)
            {
                var result = await conn.InsertAsync <PurchaseOrderLedger>(NewPurchaseOrder);

                return(result.ToString());
            }
        }
Beispiel #2
0
        /*
         * Developer: Sajid Khan
         * Date: 7-5-19
         * Action: update purchase order Ledger data by id from database
         * Input: purchase order Ledger data
         * output: Boolean
         */
        public async Task <Boolean> Update(PurchaseOrderLedger PurchaseOrdersToUpdate)
        {
            using (IDbConnection conn = Connection)
            {
                var result = await conn.UpdateAsync <PurchaseOrderLedger>(PurchaseOrdersToUpdate);

                return(result);
            }
        }
        public async Task <List <PurchaseOrderLedger> > GetAsync(int id)
        {
            List <PurchaseOrderLedger> ToReturn = new List <PurchaseOrderLedger>();

            try
            {
                PurchaseOrderLedger Res = await _PurchaseOrdersLedgerRepo.GetById(id);

                ToReturn.Add(Res);
            }
            catch (Exception ex)
            {
                var logger = _loggerFactory.CreateLogger("internal_error_log");
                logger.LogInformation("Problem happened in selecting the data for purchaseordersledger list by id with message" + ex.Message);
            }
            return(ToReturn);
        }
        public async Task <string> Update(int id, [FromBody] string value)
        {
            string UpdateResult        = "Success";
            bool   UpdateProcessOutput = false;

            try
            {
                PurchaseOrderLedger PurchaseOrdersToUpdate = JsonConvert.DeserializeObject <PurchaseOrderLedger>(value);
                PurchaseOrdersToUpdate.transaction_id = id;
                UpdateProcessOutput = await _PurchaseOrdersLedgerRepo.Update(PurchaseOrdersToUpdate);

                var eventModel = new EventModel(tableName)
                {
                    EntityId    = PurchaseOrdersToUpdate.po_id,
                    EventName   = ledger_update,
                    RefrenceId  = id,
                    UserId      = PurchaseOrdersToUpdate.updated_by,
                    EventNoteId = id
                };
                await _eventRepo.AddEventAsync(eventModel);

                var userEvent = new EventModel(userEventTableName)
                {
                    EntityId    = PurchaseOrdersToUpdate.updated_by,
                    EventName   = ledger_update,
                    RefrenceId  = id,
                    UserId      = PurchaseOrdersToUpdate.updated_by,
                    EventNoteId = id
                };
                await _eventRepo.AddEventAsync(userEvent);
            }
            catch (Exception ex)
            {
                var logger = _loggerFactory.CreateLogger("internal_error_log");
                logger.LogInformation("Problem happened in updating purchaseordersledger with message" + ex.Message);
                UpdateResult = "Failed";
            }
            if (!UpdateProcessOutput)
            {
                UpdateResult = "Creation failed due to reason: No specific reson";
            }
            return(UpdateResult);
        }
        public async Task <string> PostAsync([FromBody]   string value)
        {
            string NewInsertionID = "0";

            try
            {
                PurchaseOrderLedger newPurchaseOrder = JsonConvert.DeserializeObject <PurchaseOrderLedger>(value);
                NewInsertionID = await _PurchaseOrdersLedgerRepo.Create(newPurchaseOrder);

                var eventModel = new EventModel(tableName)
                {
                    EntityId    = newPurchaseOrder.po_id,
                    EventName   = ledger_create,
                    RefrenceId  = Int32.Parse(NewInsertionID),
                    UserId      = newPurchaseOrder.created_by,
                    EventNoteId = Convert.ToInt32(NewInsertionID)
                };
                await _eventRepo.AddEventAsync(eventModel);

                var userEvent = new EventModel(userEventTableName)
                {
                    EntityId    = newPurchaseOrder.created_by,
                    EventName   = ledger_create,
                    RefrenceId  = Convert.ToInt32(NewInsertionID),
                    UserId      = newPurchaseOrder.created_by,
                    EventNoteId = Convert.ToInt32(NewInsertionID)
                };
                await _eventRepo.AddEventAsync(userEvent);
            }
            catch (Exception ex)
            {
                var logger = _loggerFactory.CreateLogger("internal_error_log");
                logger.LogInformation("Problem happened in making new purchaseordersledger create with message" + ex.Message);
            }
            return(NewInsertionID);
        }
        public async Task <string> UpdateSpecific(int id, [FromBody] string value)
        {
            string UpdateResult = "Success";

            try
            {
                PurchaseOrderLedger PurchaseOrdersToUpdate = JsonConvert.DeserializeObject <PurchaseOrderLedger>(value);
                PurchaseOrdersToUpdate.transaction_id = id;
                Dictionary <String, String> ValuesToUpdate = new Dictionary <string, string>();

                if (PurchaseOrdersToUpdate.po_id != 0)
                {
                    ValuesToUpdate.Add("po_id", PurchaseOrdersToUpdate.po_id.ToString());
                }
                if (PurchaseOrdersToUpdate.description != null)
                {
                    ValuesToUpdate.Add("description", PurchaseOrdersToUpdate.description.ToString());
                }
                if (PurchaseOrdersToUpdate.credit != 0)
                {
                    ValuesToUpdate.Add("credit", PurchaseOrdersToUpdate.credit.ToString());
                }
                if (PurchaseOrdersToUpdate.debit != 0)
                {
                    ValuesToUpdate.Add("debit", PurchaseOrdersToUpdate.debit.ToString());
                }
                if (PurchaseOrdersToUpdate.created_by != 0)
                {
                    ValuesToUpdate.Add("created_by", PurchaseOrdersToUpdate.created_by.ToString());
                }
                if (PurchaseOrdersToUpdate.updated_by != 0)
                {
                    ValuesToUpdate.Add("updated_by", PurchaseOrdersToUpdate.updated_by.ToString());
                }
                if (PurchaseOrdersToUpdate.created_at != 0)
                {
                    ValuesToUpdate.Add("created_at", PurchaseOrdersToUpdate.created_at.ToString());
                }
                if (PurchaseOrdersToUpdate.updated_at != 0)
                {
                    ValuesToUpdate.Add("updated_at", PurchaseOrdersToUpdate.updated_at.ToString());
                }

                await _PurchaseOrdersLedgerRepo.UpdateSpecific(ValuesToUpdate, "transaction_id=" + id);

                var eventModel = new EventModel(tableName)
                {
                    EntityId    = PurchaseOrdersToUpdate.po_id,
                    EventName   = ledger_specificupdate,
                    RefrenceId  = id,
                    UserId      = PurchaseOrdersToUpdate.updated_by,
                    EventNoteId = id
                };
                await _eventRepo.AddEventAsync(eventModel);

                var userEvent = new EventModel(userEventTableName)
                {
                    EntityId    = PurchaseOrdersToUpdate.updated_by,
                    EventName   = ledger_specificupdate,
                    RefrenceId  = id,
                    UserId      = PurchaseOrdersToUpdate.updated_by,
                    EventNoteId = id
                };
                await _eventRepo.AddEventAsync(userEvent);
            }
            catch (Exception ex)
            {
                var logger = _loggerFactory.CreateLogger("internal_error_log");
                logger.LogInformation("Problem happened in updating updatespecific purchaseordersledger with message" + ex.Message);
                UpdateResult = "Failed";
            }

            return(UpdateResult);
        }