Esempio n. 1
0
        public static BodyAreaViewModel CreateBAreaViewModel(this IBodyAreaRepository bArea, IBodyPartRepository bPart, int?Id, DBGetter db)
        {
            BodyArea          bodyArea = bArea.GetBodyAreaById(Id);
            BodyAreaViewModel bAreaVM  = new BodyAreaViewModel()
            {
                Name        = bodyArea.Name,
                BodyAreaId  = bodyArea.BodyAreaId,
                Description = bodyArea.Description,
                Image       = bodyArea.Image,
                BodyParts   = bodyArea.GetBodyPartsVM(db)
            };

            return(bAreaVM);
        }
Esempio n. 2
0
        public async Task <IActionResult> Edit(BodyAreaViewModel bodyAreaModel, IFormFile file)
        {
            var      filePath = Path.GetTempFileName();
            BodyArea bArea    = new BodyArea
            {
                BodyAreaId  = bodyAreaModel.BodyAreaId,
                Name        = bodyAreaModel.Name,
                Description = bodyAreaModel.Description,
            };

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

                    bArea.Image = memoryStream.ToArray();
                }
            }
            else
            {
                bArea.Image = bodyAreaRepository.GetBodyAreaById(bodyAreaModel.BodyAreaId).Image;
            }


            if (ModelState.IsValid)
            {
                bodyAreaRepository.SaveBodyArea(bArea);
                TempData["Message"] = $"{bArea.Name} has been saved";
                return(RedirectToAction("Index"));
            }
            else
            {
                return(View(bodyAreaModel));
            }
        }