public void Edit(USAStateModel uSAStateModel) { try { USAState uSAState = dbContext.USAStates.Where(x => x.Id == uSAStateModel.Id).FirstOrDefault(); if (uSAState == null) { base.HandleError(uSAStateModel, CommonLayer.LookUps.ErrorType.Critical, null, Resources.NotFound); return; } if (Validate(uSAStateModel)) { return; } USAStateMapper.Map(dbContext, uSAStateModel, uSAState); base.SaveChanges(); uSAStateModel.AddSuccess(Resources.USAStateUpdatedSuccessfully, LookUps.SuccessType.Full); } catch (Exception ex) { base.HandleError(uSAStateModel, CommonLayer.LookUps.ErrorType.Exception, ex); base.UndoUpdates(); } }
public void Delete(USAStateModel uSAStateModel) { try { if (ValidateDelete(uSAStateModel)) { return; } USAState uSAState = dbContext.USAStates.Where(x => x.Id == uSAStateModel.Id).FirstOrDefault(); if (uSAState == null) { base.HandleError(uSAStateModel, CommonLayer.LookUps.ErrorType.Critical, null, Resources.NotFound); return; } dbContext.USAStates.Remove(uSAState); base.SaveChanges(); uSAStateModel.AddSuccess(Resources.USAStateDeletedSuccessfully, LookUps.SuccessType.Full); } catch (System.Data.Entity.Infrastructure.DbUpdateException) { base.HandleError(uSAStateModel, CommonLayer.LookUps.ErrorType.Business, null, Resources.RefrenceDeleteError); base.UndoUpdates(); } catch (Exception ex) { base.HandleError(uSAStateModel, CommonLayer.LookUps.ErrorType.Exception, ex); base.UndoUpdates(); } }
public void Create(USAStateModel uSAStateModel) { try { if (Validate(uSAStateModel)) { return; } using (var transaction = dbContext.Database.BeginTransaction()) { try { USAState uSAState = new USAState(); USAStateMapper.Map(dbContext, uSAStateModel, uSAState); uSAState.Id = Guid.NewGuid().ToString(); dbContext.USAStates.Add(uSAState); base.SaveChanges(); transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); throw ex; } uSAStateModel.AddSuccess(Resources.USAStateAddedSuccessfully, LookUps.SuccessType.Full); } } catch (Exception ex) { base.HandleError(uSAStateModel, CommonLayer.LookUps.ErrorType.Exception, ex); base.UndoUpdates(); } }