public HttpResponseMessage Create(Patient mPatient, long id) { HttpResponseMessage response = null; try { if (IsAdminPermission()) { mPatient.id = id; var patient = setPatientInfo(mPatient); var responsePatient = patientService.SavePatient(patient); response = Request.CreateResponse(HttpStatusCode.OK, responsePatient); } else { response = Request.CreateResponse(HttpStatusCode.Unauthorized); } } catch (DbEntityValidationException e) { var newException = new FormattedDbEntityValidationException(e); response = Request.CreateResponse(HttpStatusCode.InternalServerError, newException); } catch (Exception ex) { response = Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message); } return(response); }
public override int SaveChanges() { foreach (var history in ChangeTracker.Entries() .Where(e => e.Entity is IModificationHistory && (e.State == EntityState.Added || e.State == EntityState.Modified)) .Select(e => e.Entity as IModificationHistory)) { if (history == null) { continue; } history.UpdatedAt = DateTime.Now; if (history.CreatedAt == DateTime.MinValue) { history.CreatedAt = DateTime.Now; } } try { return(base.SaveChanges()); } catch (DbEntityValidationException e) { var newException = new FormattedDbEntityValidationException(e); throw newException; } }
public async Task <IHttpActionResult> PostSTANDARDData(STANDARDData sTANDARDData) { STD_Result dataResult = new STD_Result(); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { if (STANDARDDataExists(sTANDARDData.SurfaceID)) { return(Ok(sTANDARDData.SurfaceID)); } else { db.STANDARDDatas.Add(sTANDARDData); await db.SaveChangesAsync(); dataResult.StatusCode = "200"; } } catch (DbEntityValidationException e) { var newException = new FormattedDbEntityValidationException(e); Log.Info(newException); dataResult.StatusDetails = "We found the problem in 'Add CLBS process'( " + sTANDARDData.SurfaceID + ") (DateTime: " + DateTime.Now + " ). Please contact admin."; } return(Ok(dataResult.StatusCode)); }
protected bool HandleException(Action action) { try { action.Invoke(); return(true); } catch (DbEntityValidationException e) { var newException = new FormattedDbEntityValidationException(e); Failure = newException.Message; } catch (Exception ex) { var errors = new List <string>(); errors.Add(ex.Message); while (ex.InnerException != null) { errors.Add(ex.Message); ex = ex.InnerException; } Failure = string.Join(", ", errors); } return(false); }
public async Task <IHttpActionResult> PostPrismCol(PrismCol prismCol) { CRUD_Data dataResult = new CRUD_Data(); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { if (PrismColExists(prismCol.cceCode)) { return(Ok(prismCol.cceCode)); } else { db.PrismColss.Add(prismCol); await db.SaveChangesAsync(); dataResult.StatusCode = "200"; } } catch (DbEntityValidationException e) { var newException = new FormattedDbEntityValidationException(e); Log.Info(newException); dataResult.StatusDetails = "We found the problem in 'Add CLBS process'( " + prismCol.cceCode + ") (DateTime: " + DateTime.Now + " ). Please contact admin."; return(BadRequest(dataResult.StatusDetails)); } return(Ok(dataResult.StatusCode)); }
public bool CreateBankAccount(int id) { if (hasBankAccount(id) == false) { Account bankAccount = new Account(); bankAccount.UserID = id; bankAccount.TotalCash = 1000000f; try { bankDB.Accounts.Add(bankAccount); bankDB.SaveChanges(); } catch (DbEntityValidationException e) { var exception = new FormattedDbEntityValidationException(e); throw exception; } if (hasBankAccount(id)) { return(true); } else { return(false); } } else { return(false); } }
public WebsiteTemplateProject.Models.Dashboard UpsertDashboardPresets(WebsiteTemplateProject.Models.Dashboard dashboard, DashboardDBEntities2 db) { using (db) { if (dashboard.presetId == default(int)) { db.Dashboards.Add(dashboard); } else { db.Entry(dashboard).State = EntityState.Modified; } try { db.SaveChanges(); } catch (DbEntityValidationException e) { var newException = new FormattedDbEntityValidationException(e); throw newException; } return(dashboard); } }
public User UpsertWebContent(User user, MyUsersDBEntities db) { //If user is logging on after already being registered and already has a set Id, this will encrypt password, and post isLoggedIn to be true using (db) { if (user.Id == default(int)) { db.Users.Add(user); } //else //{ // db.Entry(user).State = EntityState.Modified; //} // encryptPassword(user, db); try { db.SaveChanges(); } catch (DbEntityValidationException e) { var newException = new FormattedDbEntityValidationException(e); throw newException; } return(user); } }
public async Task <IHttpActionResult> PostvUsers(Users Users) { var s = db.Users.Count(e => e.ID == Users.ID); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { if (UsersExists(Users.ID)) { return(Conflict()); } else { db.vUsers.Add(Users); await db.SaveChangesAsync(); } } catch (DbEntityValidationException e) { var newException = new FormattedDbEntityValidationException(e); throw newException; } return(Ok(200)); }
public ActionResult Register(User user) { if (ModelState.IsValid) { try { morDB.Database.ExecuteSqlCommand(user.AddUser().ToString()); //db.Users.Add(user); morDB.SaveChanges(); } catch (DbEntityValidationException e) { var exception = new FormattedDbEntityValidationException(e); throw exception; } Session.Clear(); Session["User"] = user as User; Session["UserName"] = user.UserName; Session["RoleID"] = user.UserID; Session["Cart"] = new ShoppingCart(user); return(RedirectToAction("Index", "Shop")); } return(View(user)); }
public void Update(Profile profileEntity) { if (IsValid(profileEntity)) { using (var context = new DatabaseContainer()) { profileEntity.City = context.CitySet.Find(profileEntity.CityId); context.ProfileSet.AddOrUpdate(profileEntity); try { context.SaveChanges(); } catch (DbEntityValidationException e) { var newException = new FormattedDbEntityValidationException(e); Debug.Write(newException.Message); throw newException; } catch (Exception) { throw new ArgumentException("Update Exception"); } } } }
public override int SaveChanges() { // or watch this inside exception ((System.Data.Entity.Validation.DbEntityValidationException)$exception).EntityValidationErrors // Update metafields in entitys, that implement IBaseEntity - CreatedAtDT, CreatedBy, etc var entities = ChangeTracker.Entries() .Where(x => x.Entity is IBaseEntity && (x.State == EntityState.Added || x.State == EntityState.Modified)); foreach (var entity in entities) { if (entity.State == EntityState.Added) { ((IBaseEntity)entity.Entity).CreatedAt = DateTime.Now; ((IBaseEntity)entity.Entity).CreatedBy = _userNameResolver.CurrentUserName; } ((IBaseEntity)entity.Entity).UpdatedAt = DateTime.Now; ((IBaseEntity)entity.Entity).UpdatedBy = _userNameResolver.CurrentUserName; } try { return(base.SaveChanges()); } catch (DbEntityValidationException e) { var newException = new FormattedDbEntityValidationException(e); throw newException; } }
public HttpResponseMessage UploadImage() { var httpRequest = HttpContext.Current.Request; //Upload Image var postedFormPageId = httpRequest.Form["pageId"]; if (httpRequest.Form["subPageId"] != null || postedFormSubPageId != "undefined") { postedFormSubPageId = httpRequest.Form["subPageId"]; } var postedFormUrl = httpRequest.Form["imageUrl"]; var postedBackgroundImage = httpRequest.Form["backgroundImage"]; var postedFile = httpRequest.Files["imageUrl"]; if (postedFormUrl != null && postedFile == null) { var fireBaseUrl = postedFormUrl; var pageId = Int32.Parse(postedFormPageId); var bgImage = postedBackgroundImage; if (postedFormSubPageId != null || postedFormSubPageId != "undefined") { subPageId = Int32.Parse(postedFormSubPageId); } //Save to DB using (NewWebContent1 db = new NewWebContent1()) { Models.WebContent uploadImage = new Models.WebContent() { ImageUrl = fireBaseUrl, PageId = pageId, SubPageId = subPageId, backgroundImage = fireBaseUrl //height = "500px", //backgroundRepeat = "no-repeat" }; db.WebContents.Add(uploadImage); try { db.SaveChanges(); } catch (DbEntityValidationException e) { var newException = new FormattedDbEntityValidationException(e); throw newException; } } } return(Request.CreateResponse(HttpStatusCode.Created)); }
public async System.Threading.Tasks.Task SaveAsync() { try { await Context.SaveChangesAsync(); } catch (DbEntityValidationException e) { var newException = new FormattedDbEntityValidationException(e); throw newException; } }
public override int SaveChanges() { try { return base.SaveChanges(); } catch (DbEntityValidationException e) { var newException = new FormattedDbEntityValidationException(e); throw newException; } }
public virtual void SaveChanges() { try { context.SaveChanges(); } catch (DbEntityValidationException e) { var newException = new FormattedDbEntityValidationException(e); throw newException; } }
public void Save() { try { entities.SaveChanges(); } catch (System.Data.Entity.Validation.DbEntityValidationException e) { var newException = new FormattedDbEntityValidationException(e); throw newException; } }
public override int SaveChanges() { try { return(base.SaveChanges()); } catch (DbEntityValidationException e) { var newException = new FormattedDbEntityValidationException(e); throw newException; } }
public void Commit() { try { utwk.Commit(); } catch (DbEntityValidationException e) { var newException = new FormattedDbEntityValidationException(e); throw newException; } }
public override int SaveChanges() { try { var modifiedEntries = ChangeTracker.Entries() .Where(x => x.Entity is AuditableEntity && (x.State == EntityState.Added || x.State == EntityState.Modified)); foreach (var entry in modifiedEntries) { AuditableEntity entity = entry.Entity as AuditableEntity; if (entity != null) { string identityName = ""; try { identityName = Thread.CurrentPrincipal.Identity.Name; } catch { Thread.CurrentPrincipal = new WindowsPrincipal(WindowsIdentity.GetCurrent()); identityName = Thread.CurrentPrincipal.Identity.Name; } DateTime now = DateTime.UtcNow; if (string.IsNullOrEmpty(identityName)) { identityName = "System"; } if (entry.State == EntityState.Added) { entity.CreatedBy = identityName; entity.CreatedOn = now; } else { Entry(entity).Property(x => x.CreatedBy).IsModified = false; Entry(entity).Property(x => x.CreatedOn).IsModified = false; entity.UpdatedBy = identityName; entity.UpdatedOn = now; } } } return base.SaveChanges(); } catch (DbEntityValidationException e) { var newException = new FormattedDbEntityValidationException(e); throw newException; } }
public void Commit() { base.Configuration.AutoDetectChangesEnabled = true; try { base.SaveChanges(); } catch (System.Data.Entity.Validation.DbEntityValidationException e) { var newException = new FormattedDbEntityValidationException(e); throw newException; } }
public long Insert(Order order) { db.Orders.Add(order); try { db.SaveChanges(); return(order.OrderID); } catch (DbEntityValidationException e) { var newException = new FormattedDbEntityValidationException(e); throw newException; } }
public override int SaveChanges() { // or watch this inside exception ((System.Data.Entity.Validation.DbEntityValidationException)$exception).EntityValidationErrors try { return(base.SaveChanges()); } catch (DbEntityValidationException e) { var newException = new FormattedDbEntityValidationException(e); throw newException; } }
private void OnTimedEvent(object source, ElapsedEventArgs e) { try { if (_workerIsRunning == false) { _workerIsRunning = true; ProjectInformationToGet infoToGet = null; _logger.Info($"Started looking for information to get"); //Run until queue is empty while ((infoToGet = _projectIntegrationService.GetInformationToGet()) != null) { //Set debugger on logger below to control how many cycles the service should run while debugging. var watch = System.Diagnostics.Stopwatch.StartNew(); _logger.Info($"Started Stopwatch"); _logger.Info($"Found new information, updating values"); _projectIntegrationService.AddOrUpdateNewInformation(infoToGet); _logger.Info($"Completed updating values"); watch.Stop(); _logger.Info($"Stopwatch stopped. Elapsed seconds: {watch.ElapsedMilliseconds / 1000}. " + $"Name queue items: {infoToGet.NameQueueItems.Count} " + $"Case queue items: {infoToGet.CaseQueueItems.Count} " + $"Fee calculation queue items: {infoToGet.FeeCalculationQueueItems.Count} " + $"Updated foreign keys: {infoToGet.ShouldUpdateKeys}"); } _logger.Info($"Nothing more to get from integration service right now"); _workerIsRunning = false; } else { _logger.Info($"Worker is already running! Will check back again after {_updateInterval / 1000} seconds"); } } catch (DbEntityValidationException exception) { var newException = new FormattedDbEntityValidationException(exception); HandelException(newException); throw newException; } catch (Exception exception) { HandelException(exception); //If an exception occurs when running as a service, the service will restart and run again if (Environment.UserInteractive) { throw; } } }
public HttpResponseMessage UploadAudio() { var httpRequest = HttpContext.Current.Request; //Upload Audio var postedFormPageId = httpRequest.Form["pageId"]; var postedFormColumnId = httpRequest.Form["columnId"]; var postedFormUrl = httpRequest.Form["audioUrl"]; var postedFile = httpRequest.Files["audioUrl"]; if (postedFormUrl != null && postedFile == null) { var fireBaseUrl = postedFormUrl; var pageId = Int32.Parse(postedFormPageId); var columnId = Int32.Parse(postedFormColumnId); //Save to DB using (NewWebContent1 db = new NewWebContent1()) { Models.WebContent uploadAudio = new Models.WebContent() { AudioUrl = fireBaseUrl, PageId = pageId, ColumnId = columnId, }; db.WebContents.Add(uploadAudio); try { db.SaveChanges(); } catch (DbEntityValidationException e) { var newException = new FormattedDbEntityValidationException(e); throw newException; } } } return(Request.CreateResponse(HttpStatusCode.Created)); }
public static void SafeVoidExecute(Action method) { try { method(); } catch (DbEntityValidationException e) { var newException = new FormattedDbEntityValidationException(e); KnipperRequestContext.AddError(newException.Message); } catch (Exception ex) { KnipperRequestContext.AddError(ex.Message); Log(ex); } }
public ActionResult DeleteConfirmed(int id) { Account bankAccount = bankDB.Accounts.Find(id); try { bankDB.Accounts.Remove(bankAccount); bankDB.SaveChanges(); } catch (DbEntityValidationException e) { var exception = new FormattedDbEntityValidationException(e); throw exception; } return(RedirectToAction("Index")); }
public HttpResponseMessage Create(Patient mPatient) { HttpResponseMessage response = null; try { if (IsAdminPermission()) { var patient = setPatientInfo(mPatient); var responsePatient = patientService.SavePatient(patient); mPatient.id = responsePatient.id; var patientAllergies = setAllergyList(mPatient); patientService.SaveAllergiesList(patientAllergies); var patientMedicines = setMedicinesList(mPatient); patientService.SaveMedicinesList(patientMedicines); var patientPersonalBackgrounds = setPersonalbackgroundsList(mPatient); patientService.SavePersonalBackgroundList(patientPersonalBackgrounds); var patientMotherBackgrounds = setMotherbackgroundsList(mPatient); patientService.SaveMotherBackgroundList(patientMotherBackgrounds); var patientFatherBackgrounds = setFatherbackgroundsList(mPatient); patientService.SaveFatherBackgroundList(patientFatherBackgrounds); response = Request.CreateResponse(HttpStatusCode.OK, responsePatient); } else { response = Request.CreateResponse(HttpStatusCode.Unauthorized); } } catch (DbEntityValidationException e) { var newException = new FormattedDbEntityValidationException(e); response = Request.CreateResponse(HttpStatusCode.InternalServerError, newException); } catch (Exception ex) { response = Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message); } return(response); }
public static T SafeExecute <T>(string a, bool b, string c, Func <string, bool, string, T> method) { T t = default(T); try { t = method(a, b, c); } catch (DbEntityValidationException e) { var newException = new FormattedDbEntityValidationException(e); KnipperRequestContext.AddError(newException.Message); } catch (Exception ex) { KnipperRequestContext.AddError(ex.Message); } return(t); }
public static T SafeExecuteWeb <T>(int a, int b, Func <int, int, T> method) { T t = default(T); try { t = method(a, b); } catch (DbEntityValidationException e) { var newException = new FormattedDbEntityValidationException(e); KnipperRequestContext.AddError(newException.Message); } catch (Exception ex) { KnipperRequestContext.AddError(ex.Message); Log(ex); } return(t); }
public ActionResult Create(karyawan karyawan) { try { if (ModelState.IsValid) { db.karyawan.Add(karyawan); db.SaveChanges(); return(RedirectToAction("Index")); } } catch (DbEntityValidationException e) { var newException = new FormattedDbEntityValidationException(e); //Log the error (uncomment dex variable name and add a line here to write a log. ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator."); } return(RedirectToAction("Index")); }
public override int SaveChanges() { // or watch this inside exception ((System.Data.Entity.Validation.DbEntityValidationException)$exception).EntityValidationErrors try { return base.SaveChanges(); } catch (DbEntityValidationException e) { var newException = new FormattedDbEntityValidationException(e); throw newException; } }