예제 #1
0
        public override int Update(MaterialBO bo)
        {
            var type     = MaterialTypeRepository.FindById(bo.TypeId);
            var category = MaterialCategoryRepository.FindById(bo.CategoryId);

            if (category.RequireContainer == true)
            {
                var material = Repository.FindById(bo.ContainerMaterialId);
                if (material == null)
                {
                    throw new BusinessException(ResponseCode.CannotFindMaterialById.Format(bo.ContainerMaterialId));
                }
                bo.ContainerPartNumber = material.PartNumber;
            }
            if (category.RequireRack == true)
            {
                var material = Repository.FindById(bo.RackId);
                if (material == null)
                {
                    throw new BusinessException(ResponseCode.CannotFindMaterialById.Format(bo.RackId));
                }
                bo.RackPn = material.PartNumber;
            }
            bo.CategoryId   = type.CategoryId;
            bo.CategoryCode = category.Code;
            if (bo.Configs != null && bo.Configs.Count > 0)
            {
                bo.Configs.AsParallel().ForAll(x => x.MaterialId = bo.Id);
                ConfigRepository.Delete(x => x.MaterialId == bo.Id);
                ConfigRepository.BulkInsert(Mapper.Map <List <MaterialConfig> >(bo.Configs));
            }
            return(base.Update(bo));
        }
예제 #2
0
 public UnitOfWork(EducationalMaterialDbContext context)
 {
     _context     = context;
     Author       = new AuthorRepository(_context);
     Material     = new MaterialRepository(_context);
     MaterialType = new MaterialTypeRepository(_context);
     Review       = new ReviewRepository(_context);
 }
예제 #3
0
 public UnitOfWork(CodecoolContext db)
 {
     _db           = db;
     Authors       = new AuthorRepository(_db);
     Materials     = new MaterialRepository(_db);
     MaterialTypes = new MaterialTypeRepository(_db);
     Reviews       = new ReviewRepository(_db);
     Users         = new UserRepository(_db);
 }
예제 #4
0
        public async Task RemoveLibrary_ShouldReturnsServiceResultIsSuccessfulFalse()
        {
            // Arrange
            materialTypeRepository = new MaterialTypeRepository(this.logger, false);

            // Act
            var result = await this.materialTypeRepository.RemoveLibrary(-1);

            // Assert
            Assert.AreEqual(result.IsSuccessful, false);
        }
예제 #5
0
 public UnitOfWork(ApplicationDbContext context, UserManager <ApplicationUser> userManager)
 {
     _context          = context;
     Projects          = new ProjectRepository(_context);
     Users             = new UserRepository(_context, userManager);
     Categories        = new CategoryRepository(_context);
     Materials         = new MaterialRepository(_context);
     MaterialTypes     = new MaterialTypeRepository(_context);
     Roles             = new RoleRepository(_context);
     UserProjects      = new UserProjectRepository(_context);
     ProjectCategories = new ProjectCategoryRepository(_context);
 }
예제 #6
0
        public async Task GetAllMaterialTypes_ShouldThrowResourceNotFoundException()
        {
            // Arrange
            List <MaterialTypeViewModel> materials = new List <MaterialTypeViewModel>();

            materialTypeRepository = new MaterialTypeRepository(this.logger, materials);

            // Act
            var result = await this.materialTypeRepository.GetAllMaterialTypes();

            // Assert
        }
예제 #7
0
        public async Task GetMaterialTypeById_ShouldThrowResourceNotFoundException()
        {
            // Arrange
            MaterialTypeViewModel material = null;

            materialTypeRepository = new MaterialTypeRepository(this.logger, material);

            // Act
            var result = await this.materialTypeRepository.GetMaterialTypeById(1);

            // Assert
        }
예제 #8
0
        public async Task AddMaterialType_ShouldReturnsServiceResultIsSuccessfulFalse()
        {
            // Arrange
            MaterialTypeViewModel material = new MaterialTypeViewModel()
            {
                Name = ""
            };

            materialTypeRepository = new MaterialTypeRepository(this.logger, false);

            // Act
            var result = await this.materialTypeRepository.AddMaterialType(material);

            // Assert
            Assert.AreEqual(result.IsSuccessful, false);
        }
예제 #9
0
        public async Task GetMaterialTypeById_ShouldReturnMaterialTypes()
        {
            // Arrange
            MaterialTypeViewModel material = new MaterialTypeViewModel()
            {
                Id   = 1,
                Name = "Paper"
            };

            materialTypeRepository = new MaterialTypeRepository(this.logger, material);

            // Act
            var result = await this.materialTypeRepository.GetMaterialTypeById(1);

            // Assert
            Assert.AreEqual(result.Id, 1);
        }
예제 #10
0
        public async Task UpdateLibrary_ShouldReturnsServiceResultIsSuccessfulFalse()
        {
            // Arrange
            MaterialTypeViewModel material = new MaterialTypeViewModel()
            {
                Id   = -1,
                Name = "Paper"
            };

            materialTypeRepository = new MaterialTypeRepository(this.logger, false);

            // Act
            var result = await this.materialTypeRepository.UpdateLibrary(material);

            // Assert
            Assert.AreEqual(result.IsSuccessful, false);
        }
예제 #11
0
        public async Task GetAllMaterialTypes_ShouldReturnAllMaterialTypes()
        {
            // Arrange
            List <MaterialTypeViewModel> materials = new List <MaterialTypeViewModel>()
            {
                new MaterialTypeViewModel()
                {
                    Id   = 1,
                    Name = "Paper"
                }
            };

            materialTypeRepository = new MaterialTypeRepository(this.logger, materials);

            // Act
            var result = await this.materialTypeRepository.GetAllMaterialTypes();

            // Assert
            Assert.AreEqual(result.FirstOrDefault().Id, 1);
        }
예제 #12
0
        public async Task GetMaterialTypesAsSelectListItem_ShouldReturnAllMaterialTypesAsSelectListItem()
        {
            // Arrange
            List <CustomSelectListItem> items = new List <CustomSelectListItem>()
            {
                new CustomSelectListItem()
                {
                    Text     = "1",
                    Value    = "Paper",
                    Selected = true
                }
            };

            materialTypeRepository = new MaterialTypeRepository(this.logger, items);

            // Act
            var result = await this.materialTypeRepository.GetMaterialTypesAsSelectListItem(1);

            // Assert
            Assert.AreEqual(result.Count, 1);
        }
예제 #13
0
        public override int?Add(MaterialBO bo)
        {
            var type     = MaterialTypeRepository.FindById(bo.TypeId);
            var category = MaterialCategoryRepository.FindById(bo.CategoryId);

            if (category.RequireContainer == true)
            {
                var material = Repository.FindById(bo.ContainerMaterialId);
                if (material == null)
                {
                    throw new BusinessException(ResponseCode.CannotFindMaterialById.Format(bo.ContainerMaterialId));
                }
                bo.ContainerPartNumber = material.PartNumber;
            }
            if (category.RequireRack == true)
            {
                var material = Repository.FindById(bo.RackId);
                if (material == null)
                {
                    throw new BusinessException(ResponseCode.CannotFindMaterialById.Format(bo.RackId));
                }
                bo.RackPn = material.PartNumber;
            }
            if (category.ManualPartNumber == true)  //手动输入PN
            {
                //判断用户输入的PN是否重复
                if (string.IsNullOrWhiteSpace(bo.PartNumber))
                {
                    throw new BusinessException(ResponseCode.PartNumberCannotBeNull);
                }
                else
                {
                    if (Repository.Count(x => x.PartNumber == bo.PartNumber) > 0)
                    {
                        throw new BusinessException(ResponseCode.PartNumberAlreadyExists.Format(bo.PartNumber));
                    }
                }
            }
            else
            {
                //自动生成PN
                var brand    = BrandRepository.FindById(bo.BrandId);
                var serialNo = SerialNoRepository.SingleOrDefault(x => x.BrandCode == brand.Code && x.TypeCode == type.Code);
                var number   = 1;
                if (serialNo == null)
                {
                    serialNo = new MaterialSerialNo()
                    {
                        BrandCode = brand.Code, TypeCode = type.Code, SerialNo = number
                    };
                    serialNo.SerialNo++;
                    SerialNoRepository.Insert(serialNo);
                }
                else
                {
                    if (serialNo.SerialNo >= 99)
                    {
                        throw new BusinessException(ResponseCode.MaterialCountOverLimit);
                    }
                    number = serialNo.SerialNo;
                    serialNo.SerialNo++;
                    SerialNoRepository.Update(serialNo);
                }
                var pn = $"{brand.Code}{type.Code}{number.ToString().PadLeft(2, '0')}";
                bo.PartNumber = pn;
            }

            bo.CategoryId   = type.CategoryId;
            bo.CategoryCode = category.Code;
            var id = base.Add(bo);

            if (bo.Configs != null && bo.Configs.Count > 0)
            {
                bo.Configs.AsParallel().ForAll(x => x.MaterialId = id);
                ConfigRepository.BulkInsert(Mapper.Map <List <MaterialConfig> >(bo.Configs));
            }
            return(id);
        }