Exemple #1
0
        public async Task <ActionResult <cojBGPlanWorkplan> > CreateItem(cojBGPlanWorkplan 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.cojBGPlanWorkplans.Add(newItem);
                await _context.SaveChangesAsync();

                newItem.idRef = newItem.id;

                //initial new item
                // var _item = await _context.cojBGPlanWorkplans.FindAsync (newItem.id);
                // _item.startDate = DateTime.Now.ToString (_culture);
                // _item.endDate = "31/12/9999 00:00:00";
                // _item.idRef = 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));
            }
        }
Exemple #2
0
        public async Task <IActionResult> UpdateItem(long id, cojBGPlanWorkplan item)
        {
            try
            {
                if (id != item.id)
                {
                    return(NoContent());
                }

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

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

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


                //Add new
                cojBGPlanWorkplan _itemNew = new cojBGPlanWorkplan {
                    idRef                 = item.idRef,
                    code                  = item.code,
                    name                  = item.name,
                    cojBGPlanId           = item.cojBGPlanId,
                    cojStgPlanId          = item.cojStgPlanId,
                    cojStgId              = item.cojStgId,
                    cojWorkplanTypeId     = item.cojWorkplanTypeId,
                    cojBGWorkplanId       = item.cojBGWorkplanId,
                    cojBGPlanSumA         = item.cojBGPlanSumA,
                    cojBGPlanSumB         = item.cojBGPlanSumB,
                    cojBGPlanSumC         = item.cojBGPlanSumC,
                    cojBGPlanSumAMT       = item.cojBGPlanSumAMT,
                    cojBGPlanTotalAMT     = item.cojBGPlanTotalAMT,
                    cojBGPlanTotalAMTShow = item.cojBGPlanTotalAMTShow,
                    cojAgencys            = item.cojAgencys,
                    cojAgencysFulltext    = item.cojAgencysFulltext,
                    remark                = item.remark,
                    procumentAgency       = item.procumentAgency,
                    disbursementAgency    = item.disbursementAgency,
                    responsibilityAgency  = item.responsibilityAgency
                                            // startDate = DateTime.Now.ToString (_culture),
                                            // endDate = "31/12/9999 00:00:00"
                };

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

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