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 async Task <JsonResult> Insert(MSchool school) { ErrorCodes result; string html = ""; try { result = SchoolRepository.Insert(ref school, GetLogedinUser()); } catch (ENovateException eex) { Log.Logger.Error(eex, "Failed to insert the school name: " + school.MsName); result = eex.ErrorCode; } catch (Exception ex) { Log.Logger.Error(ex, "Failed to insert the shool."); result = ErrorCodes.SaveFailure; } if (result == ErrorCodes.None) { List <MSchool> schools = SchoolRepository.GetAll(); html = await ViewRenderService.RenderViewToStringAsync("~/Areas/Admin/Views/School/_List.cshtml", schools); TempData.Put("AllSchools", schools); } string msg = (result == ErrorCodes.None) ? StringLocalizer["I.HSP-M002.0002"].Value : StringLocalizer[result.GetResourceKey()].Value; return(Json(new { status = (result == ErrorCodes.None) ? Result.Success : Result.Failure, message = msg, html })); }
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 async Task <JsonResult> Edit(string code) { var schools = TempData.Get <List <MSchool> >("AllSchools"); if (SchoolRepository.checkCondition(code) == true) { ViewData["IsCodeEditable"] = true; } else { ViewData["IsCodeEditable"] = null; } MSchool schoolitem = new MSchool(); schoolitem = schools.Where(school => school.MsCd.Equals(code)).FirstOrDefault(); TempData.Put("schoolitem", schoolitem); ViewData.Model = schoolitem; string html = await ViewRenderService.RenderViewToStringAsync("~/Areas/Admin/Views/School/_Edit.cshtml", ViewData, TempData); TempData.Keep(); return(Json(new { status = 0, schoolCode = code, html })); }