Пример #1
0
        public async Task <ActionResult <cojBGPlanAllotItem> > CreateItem(cojBGPlanAllotItem newItem)
        {
            try
            {
                //check duplicate item id, code, name
                if (newItem.id != 0)
                {
                    return(NoContent());
                }
                //
                newItem.startDate = DateTime.Now.ToString(_culture);
                newItem.endDate   = "31/12/9999 00:00:00";

                _context.cojBGPlanAllotItems.Add(newItem);
                await _context.SaveChangesAsync();

                newItem.idRef = newItem.id;

                return(CreatedAtAction(nameof(GetItem), new { id = newItem.id }, newItem));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
Пример #2
0
        public async Task <IActionResult> UpdateItem(long id, cojBGPlanAllotItem item)
        {
            try
            {
                if (id != item.id)
                {
                    return(NoContent());
                }

                //update endDate
                // var _item = await _context.cojBGPlans.FindAsync (id);
                // _item.endDate = DateTime.Now.ToString (_culture);
                // _context.Entry (_item).State = EntityState.Modified;
                // await _context.SaveChangesAsync ();

                //  var _items = await _context.cojBGPlanAllotItems.Where (a => a.idRef == item.idRef && a.endDate == "31/12/9999 00:00:00").ToListAsync ();

                // foreach (var _itm in _items) {
                //     var _item = await _context.cojBGPlanAllotItems.FindAsync (_itm.id);
                //     _item.endDate = DateTime.Now.ToString (_culture);
                //     _context.Entry (_item).State = EntityState.Modified;
                //     await _context.SaveChangesAsync ();
                // }

                //Add new
                cojBGPlanAllotItem _itemNew = new cojBGPlanAllotItem {
                    idRef                  = item.idRef,
                    cojBGPlanAllotId       = item.cojBGPlanAllotId,
                    cojBGPlanAllotToAgency = item.cojBGPlanAllotToAgency,
                    itemNO                 = item.itemNO,
                    itemName               = item.itemName,
                    itemUnit               = item.itemUnit,
                    itemUnitName           = item.itemUnitName,
                    itemUnitPrice          = item.itemUnitPrice,
                    itemParentId           = item.itemParentId,
                    itemLevel              = item.itemLevel,
                    itemAllotRequestAMT    = item.itemAllotRequestAMT,
                    itemAllotAMT           = item.itemAllotAMT,
                    itemTransferRequestAMT = item.itemTransferRequestAMT,
                    cojBGTransferRequestId = item.cojBGTransferRequestId,
                    itemTransferAMT        = item.itemTransferAMT,
                    cojBGTransferId        = item.cojBGTransferId,
                    itemTypeId             = item.itemTypeId,
                    flagIntegration        = item.flagIntegration,
                    flagRegionReserve      = item.flagRegionReserve,
                    responsibilityAgency   = item.responsibilityAgency,
                    procumentAgency        = item.procumentAgency,
                    disbursementAgency     = item.disbursementAgency,
                    flagAgencyReserve      = item.flagAgencyReserve,
                    cojFund                = item.cojFund
                                             // startDate = DateTime.Now.ToString (_culture),
                                             // endDate = "31/12/9999 00:00:00"
                };

                _context.cojBGPlanAllotItems.Add(_itemNew);
                await _context.SaveChangesAsync();

                return(Ok(_itemNew));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }