Наследование: BaseEntity
Пример #1
0
        public Dimension Update(Dimension entity)
        {
            Contract.Requires(entity != null, "provided entity can not be null");
            Contract.Requires(entity.Id >= 0, "provided entity must have a permanent ID");

            Contract.Ensures(Contract.Result<Dimension>() != null && Contract.Result<Dimension>().Id >= 0, "No entity is persisted!");

            using (IUnitOfWork uow = this.GetUnitOfWork())
            {
                IRepository<Dimension> repo = uow.GetRepository<Dimension>();
                repo.Put(entity); // Merge is required here!!!!
                uow.Commit();
            }
            return (entity);
        }
Пример #2
0
        public Dimension Create(string name, string description, string specification)
        {
            Contract.Requires(!string.IsNullOrWhiteSpace(name));
            Contract.Requires(!string.IsNullOrWhiteSpace(specification));

            Contract.Ensures(Contract.Result<Dimension>() != null && Contract.Result<Dimension>().Id >= 0);

            Dimension d = new Dimension()
            {
                Name = name,
                Description = description,
                Specification = specification,
            };

            using (IUnitOfWork uow = this.GetUnitOfWork())
            {
                IRepository<Dimension> repo = uow.GetRepository<Dimension>();
                repo.Put(d);
                uow.Commit();
            }
            return (d);
        }
Пример #3
0
        public bool Delete(Dimension entity)
        {
            Contract.Requires(entity != null);
            Contract.Requires(entity.Id >= 0);

            using (IUnitOfWork uow = this.GetUnitOfWork())
            {
                IRepository<Dimension> repo = uow.GetRepository<Dimension>();
                //entity = repo.Reload(entity);
                repo.Delete(entity);
                uow.Commit();
            }
            // if any problem was detected during the commit, an exception will be thrown!
            return (true);
        }
Пример #4
0
        public Unit Create(string name, string abbreviation, string description, Dimension dimension, MeasurementSystem measurementSystem)
        {
            Contract.Requires(!string.IsNullOrWhiteSpace(name));
            Contract.Requires(!string.IsNullOrWhiteSpace(abbreviation));
            Contract.Requires(dimension != null);

            Contract.Ensures(Contract.Result<Unit>() != null && Contract.Result<Unit>().Id >= 0);

            Unit u = new Unit()
            {
                Name = name,
                Abbreviation = abbreviation,
                Description = description,
                Dimension = dimension,
                MeasurementSystem = measurementSystem,
            };

            using (IUnitOfWork uow = this.GetUnitOfWork())
            {
                IRepository<Unit> repo = uow.GetRepository<Unit>();
                repo.Put(u);
                uow.Commit();
            }
            return (u);
        }