public IActionResult Create(Butterfly butterfly) { if (ModelState.IsValid) { var lastButterfly = _data.ButterfliesList.LastOrDefault(); butterfly.CreatedDate = DateTime.Today; if (butterfly.PhotoAvatar != null && butterfly.PhotoAvatar.Length > 0) { butterfly.ImageMimeType = butterfly.PhotoAvatar.ContentType; butterfly.ImageName = Path.GetFileName(butterfly.PhotoAvatar.FileName); butterfly.Id = lastButterfly.Id + 1; _butterfliesQuantityService.AddButterfliesQuantityData(butterfly); using (var memoryStream = new MemoryStream()) { butterfly.PhotoAvatar.CopyTo(memoryStream); butterfly.Photofile = memoryStream.ToArray(); } _data.AddButterfly(butterfly); return(RedirectToAction("Index")); } } return(View(butterfly)); }
private void InitializeButterfliesData() { if (_data.ButterfliesList == null) { List <Butterfly> butterflies = _data.ButterfliesInitializeData(); foreach (var butterfly in butterflies) { _butterfliesQuantityService.AddButterfliesQuantityData(butterfly); } } }