Esempio n. 1
0
 public IActionResult AddMaterial([FromForm] NewMaterialDto material, [FromForm] IFormFile file)
 {
     if (material.Name != null && file != null
         && file.Length < _configuration.GetValue<long>("Size"))
     {
         Material newMaterial = new Material { Name = material.Name, Category = material.Category, Extension = file.FileName.Split(".").Last() };
         var result = _materialService.AddMaterial(newMaterial, file);
         if (result != null)
             return Ok();
     }
     return BadRequest("Материал с данным именем уже существует");
 }
Esempio n. 2
0
 public IActionResult AddMaterial([FromForm] NewMaterialDto material)
 {
     if (material.Name != null && material.Category != null && material.File != null &&
         material.File.Length < 2147483648 && Categories.Contains(material.Category))
     {
         Material newMaterial = new Material {
             Name = material.Name, Category = material.Category
         };
         var result = _materialService.AddMaterial(newMaterial, material.File);
         if (result != null)
         {
             return(Ok());
         }
     }
     return(BadRequest());
 }
 public IActionResult AddMaterial([FromForm] NewMaterialDto material)
 {
     if (material.Name != null && material.Category != null && material.File != null &&
         material.File.Length < _fileSizeLimit && (Enum.IsDefined(typeof(MaterialCategories), material.Category)))
     {
         Material newMaterial = new Material
         {
             Name     = material.Name,
             Category = material.Category
         };
         var result = _materialService.AddMaterial(newMaterial, material.File);
         if (result != null)
         {
             return(Ok());
         }
     }
     return(BadRequest());
 }
Esempio n. 4
0
        private void SaveAdd_Click(object sender, RoutedEventArgs e)
        {
            string name      = textBoxName.Text;
            string priceText = textBoxPricePerGramm.Text;
            int    price     = 0;

            if (string.IsNullOrWhiteSpace(name))
            {
                errormessage.Text = "Name can`t be null or empty";
                textBoxName.Focus();
            }
            else if (!string.IsNullOrWhiteSpace(priceText) && !int.TryParse(priceText, out price) && price > 0)
            {
                errormessage.Text = "Price shoul be a naturel number";
                textBoxPricePerGramm.Focus();
            }
            else
            {
                Material newMaterial = new Material()
                {
                    Id                = Guid.NewGuid(),
                    Name              = name,
                    Description       = textBoxDescription.Text,
                    PricePerGramm     = price,
                    CreatedBy         = _rUsersService.GetCurrentUser().Id,
                    BannedInCountries = _GetSelectedCountries()
                };

                if (_rMaterialService.AddMaterial(newMaterial, out string error))
                {
                    Reset();
                    errormessage.Text = "Succesfully added!";
                }
                else
                {
                    errormessage.Text = error;
                }
            }
        }