Example #1
0
        public MaterialDto AddNew()
        {
            string name = "";

            InputBox inputBox = new InputBox("Podaj nazwę nowego surowca:", "Nazwa");

            if (inputBox.ShowDialog() == true)
            {
                name = inputBox.Answer;
            }

            if (string.IsNullOrEmpty(name))
            {
                _ = MessageBox.Show("Nazwa surowca nie może byc pusta!", "Pusta nazwa", MessageBoxButton.OK, MessageBoxImage.Warning);
                return(null);
            }

            if (_repository.ExistByName(name, MaterialRepository.ExistByNameQuery))
            {
                _ = MessageBox.Show("Surowiec o nazwie '" + name + "' istnieje już w bazie danych!", "Pusta nazwa", MessageBoxButton.OK, MessageBoxImage.Warning);
                return(null);
            }

            MaterialDto material = new MaterialDto(name)
            {
                LoginId = UserSingleton.Id
            };

            return(Save(material));
        }
Example #2
0
        public static Material MapApiToDomain(MaterialDto input)
        {
            Material output = Material.CreateDefaultInstance();

            if (input.Color != null)
            {
                output.Color.ScA = input.Color.A;
                output.Color.ScR = input.Color.R;
                output.Color.ScG = input.Color.G;
                output.Color.ScB = input.Color.B;
            }

            if (input.Ambient.HasValue)
            {
                output.Ambient = input.Ambient.Value;
            }
            if (input.Diffuse.HasValue)
            {
                output.Diffuse = input.Diffuse.Value;
            }
            if (input.Specular.HasValue)
            {
                output.Specular = input.Specular.Value;
            }
            if (input.Shininess.HasValue)
            {
                output.Shininess = input.Shininess.Value;
            }

            return(output);
        }
        public dynamic Putmaterial(int id, [FromBody] MaterialRequestDto materialDto)
        {
            MaterialDto result = null;

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != materialDto.id)
            {
                return(BadRequest());
            }
            try
            {
                result = materialRepository.updateMaterial(id, materialDto);
            }
            catch (Exception e)
            {
                if (!materialRepository.materialExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw e;
                }
            }
            return(Ok(result));
        }
Example #4
0
        public MaterialDto AddNewSemiProduct(long nrD, string name)
        {
            InputBox inputBox = new InputBox("Podaj nazwę nowego półproduktu:", name);

            if (inputBox.ShowDialog() == true)
            {
                name = inputBox.Answer;
            }
            if (string.IsNullOrEmpty(name))
            {
                _ = MessageBox.Show("Nazwa nie może być pusta", "Zła wartość", MessageBoxButton.OK, MessageBoxImage.Error);
                return(null);
            }
            if (_repository.ExistById(nrD, MaterialRepository.ExistByIntDQuery))
            {
                _ = MessageBox.Show("Półprodukt o numerze D" + nrD + " istnieje już w tabeli półprodukty.", "Brak numeru", MessageBoxButton.OK, MessageBoxImage.Information);
                return(new MaterialDto("", nrD));
            }

            MaterialDto material = new MaterialDto(name, nrD)
            {
                LoginId = UserSingleton.Id
            };

            return(Save(material));
        }
        public dynamic Postmaterial([FromBody] MaterialRequestDto materialDto)
        {
            MaterialDto result = null;

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            try
            {
                result = materialRepository.addMaterial(materialDto);
            }
            catch (Exception e)
            {
                if (materialRepository.materialExists(materialDto.id))
                {
                    return(Conflict());
                }
                else
                {
                    throw e;
                }
            }

            return(Ok(result));
        }
Example #6
0
        public IActionResult GetMaterial(int productId, int id)
        {
            //先检查是否存在
            var product = _productRepository.ProductExist(productId);

            if (!product)
            {
                return(NotFound());
            }

            var material = _productRepository.GetMaterialForProduct(productId, id);

            if (material == null)
            {
                return(NotFound());
            }
#if false //映射前
            var result = new MaterialDto
            {
                Id   = material.Id,
                Name = material.Name
            };
#endif
            var result = Mapper.Map <MaterialDto>(material);
            return(Ok(result));
        }
Example #7
0
        public void UpdateComponent(Component component, CompositionData compositionData)
        {
            MaterialRepository materialRepository = new MaterialRepository();
            MaterialDto        material           = materialRepository.GetByName(component.Name);

            component.Density        = material.Density;
            component.IsSemiProduct  = material.IsIntermediate;
            component.SemiProductNrD = material.IntermediateNrD;
            component.PriceKg        = (double)material.Price;
            component.VocPercent     = material.VOC;
            component.SemiStatus     = "";

            if (material.Id > 0)
            {
                CurrencyRepository currencyRepository = new CurrencyRepository();
                CurrencyDto        currency           = currencyRepository.GetById(material.CurrencyId, CurrencyRepository.GetByIdQuery);

                component.Rate = (double)currency.Rate;
                UpdatePriceAndVoc(component, material.VOC);
            }

            CompositionSubRecipeDto recipeDto = new CompositionSubRecipeDto(component.Id, component.Level, component.SemiProductNrD, component.Operation, component.Amount, component.Mass, component.ParentsId);

            component.SemiRecipe = component.IsSemiProduct ? GetSemiRecipe(recipeDto) : new List <Component>();
        }
Example #8
0
        //Cập nhật Brand
        public async Task <bool> Update(MaterialDto model)
        {
            var Line = _mapper.Map <Material>(model);

            _repoLine.Update(Line);
            return(await _repoLine.SaveAll());
        }
        public List <MaterialDto> GetAllMaterial()
        {
            using (ISession session = m_SessionFactory.OpenSession())
            {
                var query = session.CreateQuery("select new Material(b.Id, b.UnitId, b.Code, b.Name) "
                                                + "from Material b");

                // Get the matching objects
                var allMaterials = query.List();

                // Update Role info
                var listMaterialDtos = new List <MaterialDto>();
                foreach (Material material in allMaterials)
                {
                    var units = RetrieveEquals <Unit>("Id", material.UnitId);

                    var materialDto = new MaterialDto()
                    {
                        Id       = material.Id,
                        UnitId   = material.UnitId,
                        Code     = material.Code,
                        Name     = material.Name,
                        UnitCode = units[0].Code,
                        UnitName = units[0].Name
                    };
                    listMaterialDtos.Add(materialDto);
                }
                return(listMaterialDtos);
            }
        }
Example #10
0
        public void ClientDeletion(MaterialDto data, string userId)
        {
            var original = _repository.Get(x => x.STICKER_CODE == data.STICKER_CODE && x.WERKS == data.WERKS, null, "").FirstOrDefault();


            var datatobeclientdeleted = _repository.Get(x => x.STICKER_CODE == data.STICKER_CODE, null, "").ToList();

            foreach (var detail in datatobeclientdeleted)
            {
                if (original.CLIENT_DELETION != data.CLIENT_DELETION)
                {
                    var changes = new CHANGES_HISTORY
                    {
                        FORM_TYPE_ID  = Core.Enums.MenuList.MaterialMaster,
                        FORM_ID       = detail.STICKER_CODE + detail.WERKS,
                        FIELD_NAME    = "CLIENT_DELETION",
                        MODIFIED_BY   = userId,
                        MODIFIED_DATE = DateTime.Now,
                        OLD_VALUE     = detail.CLIENT_DELETION.HasValue ? detail.CLIENT_DELETION.Value.ToString() : "NULL",
                        NEW_VALUE     = data.CLIENT_DELETION.HasValue ? data.CLIENT_DELETION.ToString() : "NULL"
                    };

                    _changesHistoryBll.AddHistory(changes);
                }
                detail.CLIENT_DELETION = data.CLIENT_DELETION;
            }


            //_uow.SaveChanges();
        }
Example #11
0
 public async Task <IActionResult> Update(MaterialDto update)
 {
     if (await _materialService.Update(update))
     {
         return(NoContent());
     }
     return(BadRequest($"Updating Material {update.ID} failed on save"));
 }
 public async Task Insertar(MaterialDto dto)
 {
     using (var context = new DataContext())
     {
         var material = _mapper.Map <Dominio.Entidades.Material>(dto);
         await _materialRepositorio.Create(material);
     }
 }
Example #13
0
        public ActionResult Material(int id)
        {
            Material    material = db.Materials.Find(id);
            MaterialDto mDto     = GetMaterialDto(material);

            mDto.Comments = GetComments(mDto.Id);
            return(View(mDto));
        }
Example #14
0
        // ============ Methods to CREATE something ============

        /**
         * Method that will validate and create a new material in the database.
         *
         * Validations performed:
         * 1. Validation of the new material's reference (business rules);
         * 2. Validation of the new material's reference (database);
         * 3. Validation of the received info. (name, description, colors, finishes) (business rules)
         */
        public ValidationOutput Register(MaterialDto dto)
        {
            //1.
            ValidationOutput validationOutput = _materialDTOValidator.DTOReferenceIsValid(dto.Reference);

            if (validationOutput.HasErrors())
            {
                return(validationOutput);
            }

            //2.
            validationOutput = new ValidationOutputBadRequest();
            if (MaterialExists(dto.Reference))
            {
                validationOutput.AddError("Reference of material",
                                          "A material with the reference '" + dto.Reference + "' already exists in the system!");
                return(validationOutput);
            }

            //3.
            validationOutput = _materialDTOValidator.DTOIsValidForRegister(dto);
            if (validationOutput.HasErrors())
            {
                return(validationOutput);
            }

            if (dto.Colors.Count > 0)
            {
                validationOutput = PrivateAddColorsWithMaterial(dto.Colors);
                if (validationOutput.HasErrors())
                {
                    return(validationOutput);
                }
            }

            if (dto.Finishes.Count > 0)
            {
                validationOutput = PrivateAddFinishesWithMaterial(dto.Finishes);
                if (validationOutput.HasErrors())
                {
                    return(validationOutput);
                }
            }

            //NOTA: Ainda que este método verifique se o atributo Price é != null, nós, aqui no Register, nunca deixamos que seja null devido às validações
            AddNewPriceToMaterialHistory(dto);

            foreach (var finish in dto.Finishes)
            {
                finish.IsActive = true;
            }

            //If we reached here then that means we can add the new material
            validationOutput.DesiredReturn =
                _mapper.Map <MaterialDto>(
                    _materialRepository.Add(_mapper.Map <Material>(dto)));
            return(validationOutput);
        }
Example #15
0
 internal static Material MapToEntity(this MaterialDto materialDto)
 {
     return(new Material
     {
         Id = materialDto.Id,
         Name = materialDto.Name,
         MaterialColors = materialDto.Colors.Select(m => m.MapToEntity()).ToList()
     });
 }
Example #16
0
        public IEnumerable <MaterialDto> GetInfoAboutMaterial(MaterialDto dto)
        {
            if (_dbService.GetCountOfMaterials(dto.materialName) == 0)
            {
                throw new MaterialNotInDbException("Material " + dto.materialName + " is not in the database.");
            }

            return(CastToMaterialDtos(_dbService.GetMaterialsByName(dto.materialName)));
        }
        public MaterialDto getMaterial(int id)
        {
            material    m           = db.materials.Where(s => s.id == id).FirstOrDefault();
            MaterialDto materialDto = new MaterialDto(m.id, m.name, supplierRepository.getSupplier(m.supplier_infor_id), m.barcode,
                                                      materialTypeRepository.getMaterialType(m.type_id), m.main_unit, m.change_unit,
                                                      statusRepository.getStatus(m.status_id));

            return(materialDto);
        }
        public MaterialDto getMaterial(int id)
        {
            Material    m           = db.Material.Where(s => s.Id == id).FirstOrDefault();
            MaterialDto materialDto = new MaterialDto(m.Id, m.Name, supplierRepository.getSupplier(m.SupplierInforId), m.Barcode,
                                                      materialTypeRepository.getMaterialType(m.TypeId), m.ChangeUnit,
                                                      statusRepository.getStatus(m.StatusId), m.Exp);

            return(materialDto);
        }
        public async Task <ApiResult <MaterialDto> > CreateMaterial([FromBody] MaterialDto material)
        {
            var mat = _materialService.CreateMaterial(material);

            if (mat == null)
            {
                return(await Task.FromResult <ApiResult <MaterialDto> >(BadRequest("The material exist. Please enter a new material.")));
            }
            return(Ok(mat));
        }
        public dynamic Getmaterial(int id)
        {
            MaterialDto materialDto = materialRepository.getMaterial(id);

            if (materialDto == null)
            {
                return(NotFound());
            }
            return(Ok(materialDto));
        }
Example #21
0
        protected async override Task CrearNuevoElemento()
        {
            if (!string.IsNullOrWhiteSpace(Material.Descripcion) && !string.IsNullOrWhiteSpace(Material.Codigo))
            {
                await Servicios.ApiProcessor.PostApi(Material, "Material/Insert");
                await Inicializar();

                Material = new MaterialDto();
            }
        }
Example #22
0
        /**
         * Method that, if the Price attribute in the passed material is different from null, will add that price to the history of the received material.
         */
        private MaterialDto AddNewPriceToMaterialHistory(MaterialDto material)
        {
            if (material.Price != null)
            {
                material.PriceHistory.Clear();
                material.PriceHistory.Add(new PriceHistoryDto(material.Price));
            }

            return(material);
        }
        public dynamic Deletematerial(int id)
        {
            if (!materialRepository.materialExists(id))
            {
                return(NotFound());
            }

            MaterialDto materialDto = materialRepository.deleteMaterial(id);

            return(Ok(materialDto));
        }
Example #24
0
        public MaterialDto toDTO()
        {
            List <MaterialAcabamentoDto> ListaMA = new List <MaterialAcabamentoDto>();

            foreach (MaterialAcabamento ma in this.MaterialAcabamentos)
            {
                ListaMA.Add(ma.toDTO());
            }
            MaterialDto materialDto = new MaterialDto(this.Nome, ListaMA);

            return(materialDto);
        }
Example #25
0
        private MaterialDto GetMaterialDto(Material material)
        {
            MaterialDto mDto = new MaterialDto(material);

            if (material != null)
            {
                ApplicationUser user = db.Users.Find(material.AuthorId);
                mDto.FirstName = user.FirstName;
                mDto.SurName   = user.SurName;
            }
            return(mDto);
        }
Example #26
0
 public IHttpActionResult UpdateMaterial(MaterialDto m)
 {
     try
     {
         OM.UpdateMaterial(m);
         return(Ok("pppp0"));
     }
     catch (Exception e)
     {
         return(BadRequest(e.ToString()));
     }
 }
        internal List <MaterialDto> getMaterialsBySupllier(String id)
        {
            List <Material>    materials    = db.Material.Where(s => s.SupplierInforId == id && s.StatusId.Equals("CSD")).ToList();
            List <MaterialDto> materialDtos = new List <MaterialDto>();

            foreach (Material m in materials)
            {
                MaterialDto materialDto = getMaterial(m.Id);
                materialDtos.Add(materialDto);
            }
            return(materialDtos);
        }
        internal List <MaterialDto> getMaterials()
        {
            List <Material>    materials    = db.Material.ToList();
            List <MaterialDto> materialDtos = new List <MaterialDto>();

            foreach (Material m in materials)
            {
                MaterialDto materialDto = getMaterial(m.Id);
                materialDtos.Add(materialDto);
            }
            return(materialDtos);
        }
        // GET: api/materials
        public List <MaterialDto> Getmaterials()
        {
            List <material>    materials    = db.materials.ToList();
            List <MaterialDto> materialDtos = new List <MaterialDto>();

            foreach (material m in materials)
            {
                MaterialDto materialDto = materialRepository.getMaterial(m.id);
                materialDtos.Add(materialDto);
            }
            return(materialDtos);
        }
        public IHttpActionResult Getmaterial(int id)
        {
            material material = db.materials.Find(id);

            if (material == null)
            {
                return(NotFound());
            }
            MaterialDto materialDto = materialRepository.getMaterial(material.id);

            return(Ok(materialDto));
        }