Beispiel #1
0
        public async Task <IActionResult> Create(BodyPartsViewModel bodyPart, IFormFile file)
        {
            var      filePath = Path.GetTempFileName();
            BodyPart bPart    = new BodyPart
            {
                BodyPartId  = bodyPart.BodyPartId,
                Name        = bodyPart.Name,
                Description = bodyPart.Description,
                BodyAreaId  = bodyPart.BodyAreaId,
            };

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

                    bPart.Image = memoryStream.ToArray();
                }
            }

            if (ModelState.IsValid)
            {
                bodyPartRepository.SaveBodyPart(bPart);
                TempData["Message"] = $"{bodyPart.Name} has been created";
                return(RedirectToAction("Index", "BodyArea", bodyAreaRepository.BodyAreas.ToList().CreateListBAreaVM(bodyPartRepository, bodyAreaRepository, dbGetter)));
            }
            else
            {
                return(RedirectToAction("Index", "BodyArea", bodyAreaRepository.BodyAreas.ToList().CreateListBAreaVM(bodyPartRepository, bodyAreaRepository, dbGetter)));
            }
        }
Beispiel #2
0
        public ViewResult Create()
        {
            BodyPartsViewModel bPartVM = new BodyPartsViewModel
            {
                BodyAreas = bodyAreaRepository.BodyAreas.ToList()
            };

            return(View(bPartVM));
        }
Beispiel #3
0
        public IActionResult UpdateBodySize(BodyPartsViewModel model)
        {
            var userId    = User.FindFirstValue(ClaimTypes.NameIdentifier);
            var bodyParts = _bodyPartsSize.ShowUserBodyParts(userId);

            for (int i = 0; i < bodyParts.Count; i++)
            {
                bodyParts[i].LastSize    = model.bodyPartsList[i].LastSize;
                bodyParts[i].CurrentSize = model.bodyPartsList[i].CurrentSize;
            }

            _bodyPartsSize.UpdateUserBody(bodyParts);

            return(RedirectToAction("UpdateBodySize", "Account"));
        }
Beispiel #4
0
        public IActionResult UpdateBodySize()
        {
            var userId    = User.FindFirstValue(ClaimTypes.NameIdentifier);
            var bodyParts = _bodyPartsSize.ShowUserBodyParts(userId);

            var vm = new BodyPartsViewModel()
            {
                bodyPartsList = bodyParts,
                Result        = new decimal?[bodyParts.Count]
            };

            for (int i = 0; i < bodyParts.Count; i++)
            {
                vm.Result[i] = vm.bodyPartsList[i].CurrentSize - vm.bodyPartsList[i].LastSize;
            }

            return(View(vm));
        }
Beispiel #5
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));
            }
        }