public CarpetEntity NewCarpet([FromRoute] string username) { var carpet = new CarpetEntity { Username = username, Name = "Uusi matto" }; _context.Carpets.Add(carpet); _context.SaveChanges(); return(carpet); }
private async Task <bool> AddDemoData() { try { List <CarpetPropertyEntity> props = new List <CarpetPropertyEntity>(); List <CarpetColourPalletEntity> colours = new List <CarpetColourPalletEntity>(); CarpetEntity carpet = new CarpetEntity() { Name = "Empress Carpet", Description = "The Empress carpet is available in a wide range of bleach cleanable colours, making it suitable for all areas around the home excluding bathrooms. Action backed for added comfort underfoot, Empress Carpet carries a 15-year wear warranty and 20-year stain warranty.", PetFriendly = false, PriceM2 = Convert.ToDecimal(22.50), }; _dbContext.Carpets.Add(carpet); await _dbContext.SaveChangesAsync(); props.Add(new CarpetPropertyEntity() { BulletPoint = "Bleach cleanable carpet", CarpetId = carpet.Id }); props.Add(new CarpetPropertyEntity() { BulletPoint = "Suitable for all rooms excluding bathrooms", CarpetId = carpet.Id }); props.Add(new CarpetPropertyEntity() { BulletPoint = "15 - year wear warranty", CarpetId = carpet.Id }); props.Add(new CarpetPropertyEntity() { BulletPoint = "20 year stain warranty", CarpetId = carpet.Id }); props.Add(new CarpetPropertyEntity() { BulletPoint = " 100 % polypropylene", CarpetId = carpet.Id }); carpet.Propertys = props; List <CarpetImageEntity> images = new List <CarpetImageEntity>(); images.Add(new CarpetImageEntity() { ImageType = CarpetImageType.MainImage, ImageName = "Main Image", Link = "default.png", AlternateText = "Default Image", CarpetId = carpet.Id }); carpet.Images = images; carpet.Options = new List <CarpetSizeOptionEntity>(); carpet.Options.Add(new CarpetSizeOptionEntity() { Width = 3, Length = 4, M2 = 20, CarpetId = carpet.Id }); carpet.Options.Add(new CarpetSizeOptionEntity() { Width = 5, Length = 4, M2 = 35, CarpetId = carpet.Id }); carpet.Options.Add(new CarpetSizeOptionEntity() { Width = 6, Length = 4, M2 = 45, CarpetId = carpet.Id }); await _dbContext.SaveChangesAsync(); return(true); } catch (Exception ex) { return(false); } }