Esempio n. 1
0
        public async Task <IActionResult> Edit(int id, AssetGroupTbl assetGroup)
        {
            if (id != assetGroup.AssetGroupId)
            {
                return(NotFound());
            }
            if (ModelState.IsValid)
            {
                assetGroup.ModifyAtAssetGroup = DateTime.Now;
                _db.Update(assetGroup);
                await _db.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(assetGroup));
        }
Esempio n. 2
0
        public async Task <IActionResult> Create(AssetGroupTbl assetGroup)
        {
            if (ModelState.IsValid)
            {
                String idrunning = "";
                idrunning = generateRunningNumber(idrunning);

                assetGroup.AssetGroupCode      = idrunning;
                assetGroup.CreatedAtAssetGroup = DateTime.Now;
                assetGroup.ModifyAtAssetGroup  = DateTime.Now;
                _db.Add(assetGroup);
                await _db.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(assetGroup));
        }
Esempio n. 3
0
        //=========================================================================================================
        //GENERATE RUNNING NUMBER
        private String generateRunningNumber(string id)
        {
            AssetGroupTbl data = _db.AssetGroupTbl.Where(x => x.AssetGroupCode == "AG" + DateTime.Now.ToString("yyMM") + "0001").FirstOrDefault();

            string tempSubId = "";
            int    tempId;

            if (data == null)
            {
                id = "AG" + DateTime.Now.ToString("yyMM") + "0001";
            }
            else
            {
                var xx = (from a in _db.AssetGroupTbl
                          where a.AssetGroupCode.Substring(0, 6) == "AG" + DateTime.Now.ToString("yyMM")
                          select a).Max(a => a.AssetGroupCode);

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

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

            return(id);
        }