public bool Run(ContainerAlertsViewModel model, ref IQueryable <ContainerAlert> repository, IUnitOfWork unitOfWork, Response <ContainerAlertsViewModel> result, ICoreUser user)
        {
            var updatedDbModel  = unitOfWork.With <ContainerAlert>().Single(c => c.Id == model.Id); // Might be a partial class
            var newCustomResult = ContainerAlertsMapper.MapDbModelToViewModel(updatedDbModel);

            result.Data = newCustomResult;
            return(true);
        }
        public bool Run(ContainerAlertsViewModel model, ref IQueryable <ContainerAlert> repository, IUnitOfWork unitOfWork, Response <ContainerAlertsViewModel> result, ICoreUser user)
        {
            var dbModel        = repository.Single(c => c.Id == model.Id); // you need to be using the primary key could be composit
            var updatedDbModel = ContainerAlertsMapper.MapInsertModelToDbModel(model, dbModel);

            unitOfWork.With <ContainerAlert>().AddOrUpdate(updatedDbModel);
            unitOfWork.SaveChanges();
            var newCustomResult = ContainerAlertsMapper.MapDbModelToViewModel(updatedDbModel);

            result.Data = newCustomResult;
            return(true);
        }
        public Guid CreatedId; // Might be a composite key!

        public bool Run(ContainerAlertsViewModel model, IUnitOfWork unitOfWork, Response <ContainerAlertsViewModel> result, ICoreUser user)
        {
            var newCustom = ContainerAlertsMapper.MapInsertModelToDbModel(model);

            unitOfWork.With <ContainerAlert>().Add(newCustom);
            unitOfWork.SaveChanges();
            CreatedId = newCustom.Id;
            model.Id  = CreatedId; // Might be a composit key
            var newCustomResult = ContainerAlertsMapper.MapDbModelToViewModel(newCustom);

            result.Data = newCustomResult;
            return(true);
        }
Exemple #4
0
        public Response <ContainerAlertsViewModel> Run(ContainerAlertsViewModel model, ref IQueryable <ContainerAlert> repository, IUnitOfWork unitOfWork, Response <ContainerAlertsViewModel> result, ICoreUser user)
        {
            var itemToUpdate = repository.SingleOrDefault(c => c.Id == model.Id);

            if (itemToUpdate != null)
            {
                var newCustomResult = ContainerAlertsMapper.MapDbModelToViewModel(itemToUpdate);
                result.Data    = newCustomResult;
                result.Success = true;
            }
            else
            {
                result.Success = false;
                result.LogError("Error viewing ContainerAlerts");
            }

            return(result);
        }