コード例 #1
0
ファイル: MaterialSerivce.cs プロジェクト: SyPham/DMRS
        //Thêm Brand mới vào bảng Line
        public async Task <bool> Add(MaterialDto model)
        {
            var Line = _mapper.Map <Material>(model);

            _repoLine.Add(Line);
            return(await _repoLine.SaveAll());
        }
コード例 #2
0
        public ActionResult UploadMaterial(MyEventsIdentity identity, int sessionId)
        {
            if (Request.Files != null && Request.Files.Count > 0)
            {
                HttpPostedFileBase file = Request.Files[0];
                var fileBytes           = new byte[file.ContentLength];
                file.InputStream.Read(fileBytes, 0, (int)file.ContentLength);

                if (fileBytes.Length != 0)
                {
                    _authorizationService.ValidateSessionAuthorization(identity, sessionId);

                    var material = new Material
                    {
                        SessionId   = sessionId,
                        Name        = HttpUtility.HtmlDecode(file.FileName),
                        ContentType = file.ContentType,
                        Content     = fileBytes
                    };
                    _materialRepository.Add(material);
                    return(PartialView("MaterialRow", material));
                }
            }
            return(null);
        }
コード例 #3
0
ファイル: MaterialService.cs プロジェクト: war-man/TheShoes
 public Material Add(Material material)
 {
     if (_materialRepository.CheckContains(x => x.Name == material.Name))
     {
         throw new NameDuplicatedException("Tên không được trùng");
     }
     return(_materialRepository.Add(material));
 }
コード例 #4
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);
        }
コード例 #5
0
 public Material Adicionar(Material material)
 {
     material.ResultadoValidacao = new MaterialAptaParaCadastroValidation(_repository).Validate(material);
     if (PossuiConformidade(material.ResultadoValidacao))
     {
         _repository.Add(material);
     }
     return(material);
 }
コード例 #6
0
        public int Post(Material material)
        {
            if (material == null)
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.BadRequest));

            ValidateSessionAuthorization(material.SessionId);

            return _materialRepository.Add(material);
        }
コード例 #7
0
ファイル: MaterialManager.cs プロジェクト: RyanLadley/DtsOps
 public void AddMaterials(List <MaterialVendor> materialVendors, ref Error error)
 {
     foreach (var materialVendor in materialVendors)
     {
         if (materialVendor.Material.MaterialId == 0)
         {
             var newMaterial = _materialRepository.Add(materialVendor.Material.MapToEntity());
             materialVendor.Material.MaterialId = newMaterial.MaterialId;
         }
         if (materialVendor.MaterialVendorId == 0)
         {
             _materialRepository.Add(materialVendor.MapToEntity());
         }
         else
         {
             _materialRepository.Update(materialVendor.MapToEntity());
         }
     }
 }
コード例 #8
0
        public Task <bool> Handle(AddMaterialCommand message, CancellationToken cancellationToken)
        {
            if (!message.IsValid())
            {
                return(Task.FromResult(false));
            }
            var Material = new Material(Guid.NewGuid(), message.Name);

            repository.Add(Material);

            return(Task.FromResult(false));
        }
コード例 #9
0
        public IActionResult Post([FromBody] Material model)
        {
            try {
                model.CreatedOn = DateTime.Now;
                var material = _materialData.Add(model);

                _logger.LogInformation($"created /api/materials/{material.Id}");
                return(Created($"/api/materials/{material.Id}", material));
            }
            catch (Exception ex) {
                _logger.LogError($"Failed to save a new material: {ex}");
            }

            return(BadRequest("Failed to save new material"));
        }
コード例 #10
0
ファイル: MaterialService.cs プロジェクト: chechle39/fsofter
        /// <summary>
        /// Thêm 1 material sẽ tự động thêm 1 log material. bỏ cmt để xài.
        /// </summary>
        /// <param name="material">1 material cần thêm vào database</param>
        /// <returns>Material mới thêm</returns>
        public override Material Add(Material material)
        {
            var rs = materialRepository.Add(material);

            //MaterialLog mateLog = new MaterialLog()
            //{
            //    MaterialID = rs.ID,
            //    Inventory = rs.Inventory,
            //    UnitPrice = rs.UnitPrice,
            //    CreatedDate = DateTime.Now,
            //    IsDelete = false,
            //    Type = false,
            //    //EmployeeID
            //};
            //materialLogRepository.Add(mateLog);
            return(rs);
        }
コード例 #11
0
 public ActionResult Create(MaterialViewModel model)
 {
     if (ModelState.IsValid)
     {
         try
         {
             _materialRepository.Add(new Material()
             {
                 Id           = Guid.NewGuid().ToString(),
                 MaterialName = model.MaterialName,
                 Note         = model.Note
             });
             _materialRepository.Save(requestContext);
         }
         catch (Exception)
         {
             return(View());
         }
         return(RedirectToAction("Index"));
     }
     return(View());
 }
コード例 #12
0
 public Material Add(Material material)
 {
     return(materialRepository.Add(material));
 }