public async Task <IActionResult> UpdateItem(long id, cojIntegration item)
        {
            try {
                if (id != item.id)
                {
                    return(NoContent());
                }

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

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

                foreach (var _itm in _items)
                {
                    var _item = await _context.cojIntegrations.FindAsync(_itm.id);

                    _item.endDate = DateTime.Now.ToString(_culture);
                    _context.Entry(_item).State = EntityState.Modified;
                    await _context.SaveChangesAsync();
                }

                //Add new
                cojIntegration _itemNew = new cojIntegration {
                    idRef                 = item.idRef,
                    name                  = item.name,
                    cojBGPlanId           = item.cojBGPlanId,
                    cojWorkplanTypeId     = item.cojWorkplanTypeId,
                    cojBGWorkplanId       = item.cojBGWorkplanId,
                    cojWorkActivityId     = item.cojWorkActivityId,
                    cojWorkActivityItemId = item.cojWorkActivityItemId,
                    cojBudgetType         = item.cojBudgetType,
                    cojAgencyId           = item.cojAgencyId,
                    cojBGPlanAMT          = item.cojBGPlanAMT,
                    cojBGAllotAMT         = item.cojBGAllotAMT,
                    cojBGApproveAMT       = item.cojBGApproveAMT,
                    cojBGTransferAMT      = item.cojBGTransferAMT,
                    remark                = item.remark
                                            // startDate = DateTime.Now.ToString (_culture),
                                            // endDate = "31/12/9999 00:00:00"
                };

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

                return(Ok(_itemNew));
            } catch (Exception ex) {
                return(BadRequest(ex.Message));
            }
        }
        public async Task <IActionResult> DeleteItem(long id)
        {
            try
            {
                var cojDataCategory = await _context.cojDataCategorys.FindAsync(id);

                if (cojDataCategory == null)
                {
                    return(NoContent());
                }

                //update endDate
                var _item = await _context.cojDataCategorys.FindAsync(id);

                _item.endDate = DateTime.Now.ToString(_culture);
                _context.Entry(_item).State = EntityState.Modified;
                await _context.SaveChangesAsync();

                return(Ok());
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
예제 #3
0
        public async Task <IActionResult> DeleteItem(long id)
        {
            try
            {
                var _item = await _context.cojBprFunctionAuthors.FindAsync(id);

                if (_item == null)
                {
                    return(NoContent());
                }

                //update endDate

                _item.endDate = DateTime.Now.ToString(_culture);

                _item.canAccess             = false;
                _item.canCreate             = false;
                _item.canRead               = false;
                _item.canUpdate             = false;
                _item.canDelete             = false;
                _item.canGrant              = false;
                _context.Entry(_item).State = EntityState.Modified;
                await _context.SaveChangesAsync();

                return(Ok());
            }

            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
예제 #4
0
        public async Task <IActionResult> UpdateItem(long id, cojFormControl item)
        {
            try
            {
                if (id != item.id)
                {
                    return(NoContent());
                }

                //update endDate
                var _item = await _context.cojFormControls.FindAsync(id);

                _item.key         = item.key;
                _item.label       = item.label;
                _item.value       = item.value;
                _item.type        = item.type;
                _item.controlType = item.controlType;
                _item.categoryId  = item.categoryId;
                _item.required    = item.required;
                _item.order       = item.order;
                _item.options     = item.options;

                _context.Entry(_item).State = EntityState.Modified;
                await _context.SaveChangesAsync();

                return(Ok(_item));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
예제 #5
0
        public async Task <ActionResult <cojFYvalue> > CreateItem(cojFYvalue newItem)
        {
            try
            {
                _context.cojFYvalues.Add(newItem);
                await _context.SaveChangesAsync();

                //initial new item
                var _item = await _context.cojFYvalues.FindAsync(newItem.id);

                _context.Entry(_item).State = EntityState.Modified;
                await _context.SaveChangesAsync();

                return(CreatedAtAction(nameof(GetItem), new { id = newItem.id }, newItem));
            }

            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
        public async Task <IActionResult> DeleteItem(long id)
        {
            var _item = await _context.cojBGPlanWorkplanActivityGoals.FindAsync(id);

            try
            {
                if (_item == null)
                {
                    return(NoContent());
                }

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

                return(Ok());
            }

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