public async Task <IActionResult> PutSiteMasterTbl([FromRoute] long id, [FromBody] SiteMasterTbl siteMasterTbl) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != siteMasterTbl.SiteId) { return(BadRequest()); } _context.Entry(siteMasterTbl).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!SiteMasterTblExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PostSiteMasterTbl([FromBody] SiteMasterTbl siteMasterTbl) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.SiteMasterTbl.Add(siteMasterTbl); await _context.SaveChangesAsync(); return(CreatedAtAction("GetSiteMasterTbl", new { id = siteMasterTbl.SiteId }, siteMasterTbl)); }
public async Task <IActionResult> Create(SiteMasterTbl siteMaster) { if (ModelState.IsValid) { siteMaster.ModifyAtSite = DateTime.Now; siteMaster.CreatedAtSite = DateTime.Now; _db.Add(siteMaster); await _db.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(siteMaster)); }
public async Task <IActionResult> Create(SiteMasterTbl siteMaster) { if (ModelState.IsValid) { String idrunning = ""; idrunning = generateRunningNumber(idrunning); siteMaster.SiteCode = idrunning; siteMaster.ModifyAtSite = DateTime.Now; siteMaster.CreatedAtSite = DateTime.Now; _db.Add(siteMaster); await _db.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(siteMaster)); }
public async Task <IActionResult> Edit(long id, SiteMasterTbl siteMaster) { // var create = _db.SiteMasterTbl.Where(m => m.SiteId == siteMaster.SiteId).First().CreatedAtSite; if (id != siteMaster.SiteId) { return(NotFound()); } if (ModelState.IsValid) { // //siteMaster.CreatedAtSite = create; siteMaster.ModifyAtSite = DateTime.Now; _db.Update(siteMaster); _db.SaveChanges(); return(RedirectToAction(nameof(Index))); } return(View(siteMaster)); }
//========================================================================================================= //GENERATE RUNNING NUMBER private String generateRunningNumber(string id) { SiteMasterTbl data = _db.SiteMasterTbl.Where(x => x.SiteCode == "ST" + DateTime.Now.ToString("yyMM") + "0001").FirstOrDefault(); string tempSubId = ""; int tempId; if (data == null) { id = "ST" + DateTime.Now.ToString("yyMM") + "0001"; } else { var xx = (from a in _db.SiteMasterTbl where a.SiteCode.Substring(0, 6) == "ST" + DateTime.Now.ToString("yyMM") select a).Max(a => a.SiteCode); tempSubId = xx.Substring(6, 4); tempId = Convert.ToInt32(tempSubId); tempId = tempId + 1; if (tempId.ToString().Length == 1) { id = "ST" + DateTime.Now.ToString("yyMM") + "000" + tempId; } else if (tempId.ToString().Length == 2) { id = "ST" + DateTime.Now.ToString("yyMM") + "00" + tempId; } else if (tempId.ToString().Length == 3) { id = "ST" + DateTime.Now.ToString("yyMM") + "0" + tempId; } else if (tempId.ToString().Length == 4) { id = "ST" + DateTime.Now.ToString("yyMM") + tempId; } } return(id); }