//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()); }
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); }
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)); }
// ============ 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); }
public Material Adicionar(Material material) { material.ResultadoValidacao = new MaterialAptaParaCadastroValidation(_repository).Validate(material); if (PossuiConformidade(material.ResultadoValidacao)) { _repository.Add(material); } return(material); }
public int Post(Material material) { if (material == null) throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.BadRequest)); ValidateSessionAuthorization(material.SessionId); return _materialRepository.Add(material); }
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()); } } }
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)); }
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")); }
/// <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); }
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()); }
public Material Add(Material material) { return(materialRepository.Add(material)); }