Пример #1
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();
            }
        }
Пример #2
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();
            }
        }
Пример #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 PrepareUSAStateModel(USAStateModel uSAStateModel)
 {
     try
     {
     }
     catch (Exception ex)
     {
         base.HandleError(uSAStateModel, CommonLayer.LookUps.ErrorType.Critical, ex);
     }
 }
Пример #5
0
 public TruckLoadModel()
 {
     TruckModel     = new TruckModel(false);
     DriverModel    = new DriverModel(false);
     CompanyModel   = new CompanyModel(false);
     StatusModel    = new StatusModel(false);
     FromStateModel = new USAStateModel(false);
     ToStateModel   = new USAStateModel(false);
     StatesList     = new List <SelectListItem>();
     StatusesList   = new List <SelectListItem>();
 }
Пример #6
0
        public ActionResult Create(BaseModel baseModel)
        {
            USAStateModel uSAStateModel = new USAStateModel();

            uSAStateModel.CopyBaseModel(baseModel);

            using (USAStateBAL uSAStateBAL = new USAStateBAL(ContextInfo))
            {
                uSAStateBAL.PrepareUSAStateModel(uSAStateModel);
            }

            return(View("Create", uSAStateModel));
        }
Пример #7
0
        public ActionResult View(string id)
        {
            USAStateModel uSAStateModel = new USAStateModel();

            uSAStateModel.Id = id;

            using (USAStateBAL uSAStateBAL = new USAStateBAL(ContextInfo))
            {
                uSAStateBAL.GetUSAStateModel(uSAStateModel);
                // uSAStateBAL.PrepareUSAStateModel(uSAStateModel);
            }

            return(View(uSAStateModel));
        }
Пример #8
0
        public static void Map(LMYFrameWorkMVCEntities dbContext, List <USAState> src, List <USAStateModel> dest)
        {
            if (src == null || dest == null)
            {
                return;
            }

            foreach (USAState uSAState in src)
            {
                USAStateModel uSAStateModel = new USAStateModel();
                Map(dbContext, uSAState, uSAStateModel);
                dest.Add(uSAStateModel);
            }
        }
Пример #9
0
        private bool Validate(USAStateModel uSAStateModel)
        {
            if (dbContext.USAStates.Any(x => x.Name == uSAStateModel.Name && x.Id != uSAStateModel.Id.ToString()))
            {
                base.HandleError(uSAStateModel, CommonLayer.LookUps.ErrorType.Business, null, string.Format(Resources.AlreadyExists, uSAStateModel.GetDisplayName(x => x.Name)), uSAStateModel.nameof(x => x.Name));
            }


            if (dbContext.USAStates.Any(x => x.StateCode.ToLower() == uSAStateModel.StateCode.ToLower() && x.Id != uSAStateModel.Id.ToString()))
            {
                base.HandleError(uSAStateModel, CommonLayer.LookUps.ErrorType.Business, null, string.Format(Resources.AlreadyExists, uSAStateModel.GetDisplayName(x => x.StateCode)), uSAStateModel.nameof(x => x.StateCode));
            }

            return(uSAStateModel.HasErrorByType());
        }
Пример #10
0
        // GET: USAState/Edit/5
        public ActionResult Edit(string id, BaseModel baseModel)
        {
            USAStateModel uSAStateModel = new USAStateModel();

            uSAStateModel.CopyBaseModel(baseModel);
            uSAStateModel.Id = id;

            using (USAStateBAL uSAStateBAL = new USAStateBAL(ContextInfo))
            {
                uSAStateBAL.GetUSAStateModel(uSAStateModel);
                uSAStateBAL.PrepareUSAStateModel(uSAStateModel);
            }

            return(View(uSAStateModel));
        }
Пример #11
0
        public ActionResult Delete(USAStateModel uSAStateModel)
        {
            using (USAStateBAL uSAStateBAL = new USAStateBAL(ContextInfo))
            {
                uSAStateBAL.Delete(uSAStateModel);

                if (uSAStateModel.HasErrorByType())
                {
                    uSAStateBAL.GetUSAStateModel(uSAStateModel);
                    //     uSAStateBAL.PrepareUSAStateModel(uSAStateModel);
                }
            }

            return(View(uSAStateModel));
        }
Пример #12
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);
            }
        }
Пример #13
0
        public ActionResult Create(USAStateModel uSAStateModel)
        {
            using (USAStateBAL uSAStateBAL = new USAStateBAL(ContextInfo))
            {
                if (ModelState.IsValid)
                {
                    uSAStateBAL.Create(uSAStateModel);
                }

                if (uSAStateModel.HasErrorByType(LMYFrameWorkMVC.Common.LookUps.ErrorType.Critical) || uSAStateModel.HasSuccess(LMYFrameWorkMVC.Common.LookUps.SuccessType.Full))
                {
                    return(base.RedirectToActionWithData(new Dictionary <string, object> {
                        { "baseModel", uSAStateModel }
                    }));
                }

                uSAStateBAL.PrepareUSAStateModel(uSAStateModel);
            }

            return(View("Create", uSAStateModel));
        }
Пример #14
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();
            }
        }
Пример #15
0
 private bool ValidateDelete(USAStateModel uSAStateModel)
 {
     return(uSAStateModel.HasErrorByType());
 }
Пример #16
0
 // GET: USAState
 public ActionResult Index(USAStateModel returnedModel)
 {
     return(View(returnedModel));
 }