Ejemplo n.º 1
0
 public async Task <IActionResult> Edit(long id, [Bind("AssetId,AssetGroupId,SiteId,EntityId,AssetCode,AssetName,SerialNumber,ValidityDate,Location,Valuation,CreatedAtAsset,ModifyAtAsset")] AssetTbl assetTbl)
 {
     if (ModelState.IsValid)
     {
         try
         {
             assetTbl.ModifyAtAsset = DateTime.Now;
             _context.Update(assetTbl);
             await _context.SaveChangesAsync();
         }
         catch (DbUpdateConcurrencyException)
         {
             if (!AssetTblExists(assetTbl.AssetId))
             {
                 return(NotFound());
             }
             else
             {
                 throw;
             }
         }
         return(RedirectToAction(nameof(Index)));
     }
     return(View(assetTbl));
 }
Ejemplo n.º 2
0
        public async Task <IActionResult> Create([Bind("AssetId,AssetGroupId,SiteId,EntityId,AssetCode,AssetName,SerialNumber,ValidityDate,Location,Valuation,CreatedAtAsset,ModifyAtAsset")] AssetTbl assetTbl)
        {
            if (ModelState.IsValid)
            {
                String idrunning = "";
                idrunning = generateRunningNumber(idrunning);

                assetTbl.AssetCode      = idrunning;
                assetTbl.CreatedAtAsset = DateTime.Now;
                assetTbl.ModifyAtAsset  = DateTime.Now;
                _context.Add(assetTbl);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(assetTbl));
        }
Ejemplo n.º 3
0
        //=============================================================================================================
        //GENERATE RUNNING NUMBER
        private String generateRunningNumber(string id)
        {
            AssetTbl data = _context.AssetTbl.Where(x => x.AssetCode == "AS" + DateTime.Now.ToString("yyMM") + "0001").FirstOrDefault();

            string tempSubId = "";
            int    tempId;

            if (data == null)
            {
                id = "AS" + DateTime.Now.ToString("yyMM") + "0001";
            }
            else
            {
                var xx = (from a in _context.AssetTbl
                          where a.AssetCode.Substring(0, 6) == "ST" + DateTime.Now.ToString("yyMM")
                          select a).Max(a => a.AssetCode);

                tempSubId = xx.Substring(6, 4);
                tempId    = Convert.ToInt32(tempSubId);
                tempId    = tempId + 1;

                if (tempId.ToString().Length == 1)
                {
                    id = "AS" + DateTime.Now.ToString("yyMM") + "000" + tempId;
                }
                else if (tempId.ToString().Length == 2)
                {
                    id = "AS" + DateTime.Now.ToString("yyMM") + "00" + tempId;
                }
                else if (tempId.ToString().Length == 3)
                {
                    id = "AS" + DateTime.Now.ToString("yyMM") + "0" + tempId;
                }
                else if (tempId.ToString().Length == 4)
                {
                    id = "AS" + DateTime.Now.ToString("yyMM") + tempId;
                }
            }

            return(id);
        }