public IActionResult Post([FromBody] Day day) { if (day == null) { return(BadRequest()); } db.Day.Add(day); db.SaveChanges(); return(Ok(day)); }
public APIDayController(OneDayFlatContext context) { this.db = context; if (!db.Day.Any()) { db.Day.Add(new Day { Booked = true }); db.Day.Add(new Day { Booked = false }); db.SaveChanges(); } }
public IActionResult Create(FlatViewImage pvm) { Flat flat = new Flat { OwnerName = pvm.OwnerName, PhoneNumber = pvm.PhoneNumber, Description = pvm.Description, Price = pvm.Price }; if (pvm.Days == null) { List <Day> DaysList = new List <Day>(); int a = 30; while (a > 0) { DaysList.Add(new Day { Booked = false }); --a; } flat.Days = DaysList; } if (pvm.Image != null) { byte[] imageData = null; // считываем переданный файл в массив байтов using (var binaryReader = new BinaryReader(pvm.Image.OpenReadStream())) { imageData = binaryReader.ReadBytes((int)pvm.Image.Length); } // установка массива байтов flat.Image = imageData; } _context.Flat.Add(flat); _context.SaveChanges(); return(View(flat)); }