public ActionResult DeleteConfirmed(string id) { MasCity masCity = db.MasCities.Find(id); db.MasCities.Remove(masCity); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "WSysCode,WSysCreateCode,WSysCreateUtc,WSysUpdateCode,WSysUpdateUtc,WSysStatusFlg,WSysIsDelete,WCountryCode,WName")] MasCity masCity) { if (ModelState.IsValid) { db.Entry(masCity).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(masCity)); }
public ActionResult Create([Bind(Include = "WSysCode,WSysCreateCode,WSysCreateUtc,WSysUpdateCode,WSysUpdateUtc,WSysStatusFlg,WSysIsDelete,WCountryCode,WName")] MasCity masCity) { if (ModelState.IsValid) { db.MasCities.Add(masCity); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(masCity)); }
// GET: Root/MasCities/Delete/5 public ActionResult Delete(string id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } MasCity masCity = db.MasCities.Find(id); if (masCity == null) { return(HttpNotFound()); } return(View(masCity)); }
public ApiModel Update(MasCity model) { // Check existed record by update date var currentEntry = this.ReadOne(model.WSysCode, model.WSysUpdateUtc); // Return api model var apiModel = new ApiModel(); if (currentEntry == null) { apiModel.RtnMessage = "The data has been update by another user. Please reload page."; //TODO return(apiModel); } // Check status if ((int)RepoConst.WSysStatus.Delete == model.WSysStatusFlg) { model.WSysIsDelete = (int)RepoConst.WSysIsDelete.Yes; } // Get UTC datetime var utcNow = DateTime.UtcNow; // Init data model.WSysUpdateCode = "login code"; // TODO model.WSysUpdateUtc = utcNow; try { // To database this.DbRepository.Entry(currentEntry).CurrentValues.SetValues(model); this.DbRepository.Entry(currentEntry).State = EntityState.Modified; // Save update data this.DbRepository.SaveChanges(); apiModel.RtnData = model.WName; } catch (Exception ex) { LogProvider.Instance.LogError(ex); apiModel.RtnCode = (int)RepoConst.ApiState.False; apiModel.RtnMessage = ex.InnerException == null ? ex.Message : ex.InnerException?.Message; } return(apiModel); }
public ApiModel ReadOne(MasCity model) { // Return api model var apiModel = new ApiModel(); try { // Add to database apiModel.RtnData = this.DbRepository.MasCities.Where(entry => entry.WSysCode == model.WSysCode).FirstOrDefault(); apiModel.RtnMessage = this.DbRepository.MasCities.Where(entry => entry.WSysCode == model.WSysCode).Count().ToString(); } catch (Exception ex) { LogProvider.Instance.LogError(ex); apiModel.RtnCode = (int)RepoConst.ApiState.False; apiModel.RtnMessage = ex.InnerException == null ? ex.Message : ex.InnerException?.Message; } return(apiModel); }
public ApiModel Create(MasCity model) { // Get UTC datetime var utcNow = DateTime.UtcNow; // Model Code model.WSysCode = RepoUtility.GuidCode(); // Init data model.WSysStatusFlg = (int)RepoConst.WSysStatus.Active; model.WSysIsDelete = (int)RepoConst.WSysIsDelete.No; model.WSysCreateCode = "login code"; // TODO model.WSysCreateUtc = utcNow; model.WSysUpdateCode = "login code"; // TODO model.WSysUpdateUtc = utcNow; // Return api model var apiModel = new ApiModel(); try { // To database this.DbRepository.MasCities.Add(model); // Save data this.DbRepository.SaveChangesAsync(); apiModel.RtnData = model.WName; } catch (Exception ex) { LogProvider.Instance.LogError(ex); apiModel.RtnCode = (int)RepoConst.ApiState.False; apiModel.RtnMessage = ex.InnerException == null ? ex.Message : ex.InnerException?.Message; } return(apiModel); }