public ErrorCodes Update(ref MMeasurementTag tag, MSystemUser user) { Log.Logger.Information("Update a seminar tag {@tag}", tag); using (var transaction = DbContext.Database.BeginTransaction()) { MMeasurementTag originalTag = DbContext.MMeasurementTag.Find(tag.MmtId); if (!originalTag.MmtUpdateDatetime.Equals(tag.MmtUpdateDatetime)) { return(ErrorCodes.DataIntegrity); } originalTag.UpdateTagInfo(tag); originalTag.UpdateEditingInfo(user); originalTag.EnsureTagInfoNotNull(); DbContext.Update(originalTag); int effectedRows = DbContext.SaveChanges(); if (effectedRows != 1) { transaction.Rollback(); return(ErrorCodes.SaveFailure); } transaction.Commit(); tag = originalTag; } Log.Logger.Information("Update sucessfully"); return(ErrorCodes.None); }
public ErrorCodes Delete(string id, MSystemUser user) { using (var transaction = DbContext.Database.BeginTransaction()) { if (checkCondition(id) == true) { var deleteSchool = (from c in DbContext.MSchool where c.MsCd == id select c).SingleOrDefault(); if (deleteSchool.MsDeleteDatetime != null) { return(ErrorCodes.DataIntegrity); } deleteSchool.MsDeleteDatetime = DateTime.Now; DbContext.MSchool.Update(deleteSchool); int effectRow = DbContext.SaveChanges(); if (effectRow != 1) { transaction.Rollback(); return(ErrorCodes.NotDeleteID); } } else { return(ErrorCodes.IdSchoolWasUse); } transaction.Commit(); } Log.Logger.Information("Delete successfully"); return(ErrorCodes.None); }
public ErrorCodes Insert(ref MSchool school, MSystemUser user) { Log.Logger.Information("Update a new school {@mSchool}", school); using (var transaction = DbContext.Database.BeginTransaction()) { if (CheckDuplicateCode(school.MsCd) == true) { school.UpdateCreatingInfo(user); DbContext.MSchool.Add(school); int effectRow = DbContext.SaveChanges(); if (effectRow != 1) { transaction.Rollback(); return(ErrorCodes.SaveFailure); } } else { return(ErrorCodes.IdSchoolDuplicate); } transaction.Commit(); } Log.Logger.Information("Insert successfully"); return(ErrorCodes.None); }
public IActionResult GetData() { var model = new MSystemUser() { MsuName = StringLocalizer["Sample"].Value }; return(View(model)); }
public ErrorCodes Update(ref MSchool school, MSystemUser user, string id) { Log.Logger.Information("Update a new school {@mSchool}", school); using (var transaction = DbContext.Database.BeginTransaction()) { int effectRow = 0; var updateschool = DbContext.MSchool.Find(id); if (!updateschool.MsUpdateDatetime.Equals(school.MsUpdateDatetime)) { return(ErrorCodes.DataIntegrity); } if (school.MsCd != id) { if (CheckDuplicateCode(school.MsCd) == true) { DbContext.MSchool.Remove(updateschool); effectRow = DbContext.SaveChanges(); if (effectRow != 1) { transaction.Rollback(); return(ErrorCodes.SaveFailure); } //updateschool.MsCd = school.MsCd; //updateschool.MsName = school.MsName; //updateschool.MsNameEng = school.MsNameEng; school.UpdateEditingInfo(user); DbContext.MSchool.Add(school); effectRow = DbContext.SaveChanges(); } else { return(ErrorCodes.IdSchoolDuplicate); } } else { school.MsCd = id; school.UpdateEditingInfo(user); DbContext.MSchool.Update(school); effectRow = DbContext.SaveChanges(); } if (effectRow != 1) { transaction.Rollback(); return(ErrorCodes.SaveFailure); } transaction.Commit(); } Log.Logger.Information("Update successfully"); return(ErrorCodes.None); }
public ErrorCodes Insert(ref MMeasurementTag tag, MSystemUser user) { Log.Logger.Information("Insert a new seminar tag {@tag}", tag); using (var transaction = DbContext.Database.BeginTransaction()) { tag.UpdateCreatingInfo(user); tag.EnsureTagInfoNotNull(); DbContext.Add(tag); int effectedRows = DbContext.SaveChanges(); if (effectedRows != 1) { transaction.Rollback(); return(ErrorCodes.SaveFailure); } transaction.Commit(); } Log.Logger.Information("Insert successfully"); return(ErrorCodes.None); }
public async Task <IActionResult> Index() //public IActionResult Index() { // Below code just for example to use ViewRenderService only var user = new MSystemUser() { MsuName = "Sample Name", Authorities = Authorities.SystemManager }; //Fake user HttpContext.Session.SetObject("LogedinUser", user); //var result = await ViewRenderService.RenderViewToStringAsync("Home/About", user); or ViewData["sample"] = "Sample Data"; var result = await ViewRenderService.RenderViewToStringAsync("Home/About", user); return(Content(result)); //return View(); }
public override void OnActionExecuting(ActionExecutingContext context) { // Check session timeout MSystemUser user = context.HttpContext.Session.GetObject <MSystemUser>("LogedinUser"); if (user == null) { context.Result = new RedirectResult("/Home/Index"); Log.Logger.Warning("Session timeout."); return; } // Check Authorities if ((user.Authorities & AllowedAuthorities) == 0) { context.Result = new RedirectResult("/Home/Index"); Log.Logger.Warning("The user dont have authority to access page: " + context.HttpContext.Request.Path); return; } base.OnActionExecuting(context); }