Exemplo n.º 1
0
        public async Task <IActionResult> Edit(BodyPartsViewModel bodyPartVM, IFormFile file)
        {
            var      filePath = Path.GetTempFileName();
            BodyPart bPart    = new BodyPart
            {
                BodyPartId  = bodyPartVM.BodyPartId,
                Name        = bodyPartVM.Name,
                Description = bodyPartVM.Description,
                BodyAreaId  = bodyPartVM.BodyAreaId,
            };

            if (file != null)
            {
                using (var memoryStream = new MemoryStream())
                {
                    await file.CopyToAsync(memoryStream);

                    bPart.Image = memoryStream.ToArray();
                }
            }
            else
            {
                bPart.Image = bodyPartRepository.GetBodyPartById(bPart.BodyPartId).Image;
            }


            if (ModelState.IsValid)
            {
                bodyPartRepository.SaveBodyPart(bPart);
                TempData["Message"] = $"{bPart.Name} has been saved";
                return(RedirectToAction("Index", "BodyArea"));
            }
            else
            {
                return(View(bodyPartVM));
            }
        }
Exemplo n.º 2
0
        public static BodyPartsViewModel CreateBPartViewModel(this IBodyPartRepository bPart, IBodyAreaRepository bodyArea, int?Id, DBGetter db)
        {
            BodyPart           bodyPart = bPart.GetBodyPartById(Id);
            BodyPartsViewModel bPartVM  = new BodyPartsViewModel()
            {
                Name        = bodyPart.Name,
                BodyAreaId  = bodyPart.BodyAreaId,
                Description = bodyPart.Description,
                Image       = bodyPart.Image,
                BodyPartId  = bodyPart.BodyPartId,
                BodyAreas   = bodyArea.BodyAreas.ToList(),
                Muscles     = bodyPart.GetListMuscleVM(db)
            };

            return(bPartVM);
        }