示例#1
0
        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();
            }
        }
示例#2
0
        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();
            }
        }
示例#3
0
        public static void Map(LMYFrameWorkMVCEntities dbContext, USAStateModel src, USAState dest)
        {
            if (src == null || dest == null)
            {
                return;
            }

            dest.CopyPropertyValues(src);
        }
示例#4
0
        public void GetUSAStateModel(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);
                }
                else
                {
                    USAStateMapper.Map(dbContext, uSAState, uSAStateModel);
                }
            }
            catch (Exception ex)
            {
                base.HandleError(uSAStateModel, CommonLayer.LookUps.ErrorType.Critical, ex);
            }
        }
示例#5
0
        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();
            }
        }