Esempio n. 1
0
        public void Edit(TruckLoadModel truckLoadModel)
        {
            try
            {
                Common.DAL.TruckLoad load = dbContext.TruckLoads.Where(x => x.Id == truckLoadModel.Id).FirstOrDefault();

                if (load == null)
                {
                    base.HandleError(truckLoadModel, CommonLayer.LookUps.ErrorType.Critical, null, Resources.NotFound);
                    return;
                }

                if (Validate(truckLoadModel))
                {
                    return;
                }

                TruckLoadMapper.Map(dbContext, truckLoadModel, load);

                base.SaveChanges();

                truckLoadModel.AddSuccess(Resources.LoadUpdatedSuccessfully, LookUps.SuccessType.Full);
            }
            catch (Exception ex)
            {
                base.HandleError(truckLoadModel, CommonLayer.LookUps.ErrorType.Exception, ex);
                base.UndoUpdates();
            }
        }
Esempio n. 2
0
        public void Delete(TruckLoadModel truckLoadModel)
        {
            try
            {
                if (ValidateDelete(truckLoadModel))
                {
                    return;
                }

                Common.DAL.TruckLoad load = dbContext.TruckLoads.Where(x => x.Id == truckLoadModel.Id).FirstOrDefault();

                if (load == null)
                {
                    base.HandleError(truckLoadModel, CommonLayer.LookUps.ErrorType.Critical, null, Resources.NotFound);
                    return;
                }

                dbContext.TruckLoads.Remove(load);

                base.SaveChanges();

                truckLoadModel.AddSuccess(Resources.LoadDeletedSuccessfully, LookUps.SuccessType.Full);
            }
            catch (System.Data.Entity.Infrastructure.DbUpdateException)
            {
                base.HandleError(truckLoadModel, CommonLayer.LookUps.ErrorType.Business, null, Resources.RefrenceDeleteError);
                base.UndoUpdates();
            }
            catch (Exception ex)
            {
                base.HandleError(truckLoadModel, CommonLayer.LookUps.ErrorType.Exception, ex);
                base.UndoUpdates();
            }
        }
Esempio n. 3
0
        public void Create(TruckLoadModel truckLoadModel)
        {
            try
            {
                if (Validate(truckLoadModel))
                {
                    return;
                }

                using (var transaction = dbContext.Database.BeginTransaction())
                {
                    try
                    {
                        Common.DAL.TruckLoad truckLoad = new Common.DAL.TruckLoad();

                        TruckLoadMapper.Map(dbContext, truckLoadModel, truckLoad);

                        truckLoad.Id = Guid.NewGuid().ToString();

                        dbContext.TruckLoads.Add(truckLoad);

                        base.SaveChanges();
                        transaction.Commit();
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();
                        throw ex;
                    }

                    truckLoadModel.AddSuccess(Resources.LoadAddedSuccessfully, LookUps.SuccessType.Full);
                }
            }
            catch (Exception ex)
            {
                base.HandleError(truckLoadModel, CommonLayer.LookUps.ErrorType.Exception, ex);
                base.UndoUpdates();
            }
        }