Пример #1
0
        public async Task <IActionResult> CreateModel([FromForm] CreateModelDTO formmodel)
        {
            try
            {
                IFormFile file            = Request.Form.Files[0];
                var       containerClient = _blobServiceClient.GetBlobContainerClient("images");
                var       blobClient      = containerClient.GetBlobClient(file.FileName);
                await blobClient.UploadAsync(file.OpenReadStream(), new BlobHttpHeaders { ContentType = file.ContentType });

                var url = blobClient.Uri.AbsoluteUri;
                formmodel.imgurl = url;
                var m = await _adminservice.CreateModel(formmodel);

                return(StatusCode(201, m));
            }
            catch (Exception e)
            {
                if (e.Message.Length > 0)
                {
                    return(BadRequest(e.Message));
                }
                else
                {
                    throw;
                }
            }
        }
Пример #2
0
        public async Task <ModelDTO> CreateModel(CreateModelDTO model)
        {
            if (model.Price == 0)
            {
                throw new Exception("Price cannot be 0.");
            }
            var m = model.AsModel();
            await _context.Models.AddAsync(m);

            await _context.SaveChangesAsync();

            return(m.AsDTO());
        }
Пример #3
0
 public static Models AsModel(this CreateModelDTO model)
 {
     return(new Models
     {
         ProductID = model.ProductID,
         Colour = model.Colour,
         Size = model.Size,
         Stock = model.Stock,
         Price = model.Price,
         imgurl = model.imgurl,
         BrandID = model.BrandID,
         SubCategoryID = model.SubCategoryID,
         CategoryID = model.CategoryID
     });
 }