예제 #1
0
        public async Task <IActionResult> UpdateAnimal([Bind] LiveAnimalViewModel model, ICollection <IFormFile> files)
        {
            ViewBag.Categories = await _adminPanelServices.GetCategoryList();

            if (ModelState.IsValid == false)
            {
                return(View(model));
            }
            var newImages = await _adminPanelServices.UploadImage(files);

            _logger.LogInformation($"UpdateAnimal New Images: {JsonConvert.SerializeObject(newImages)}");

            if (model != null)
            {
                var item = await _adminPanelServices.GetAnimalDetails(model.Id);

                var existingImages = item?.Images;
                if (existingImages == null)
                {
                    existingImages = new List <string>();
                }
                existingImages.AddRange(newImages);

                _logger.LogInformation($"UpdateAnimal Final Images: {JsonConvert.SerializeObject(existingImages)}");

                model.Images     = existingImages;
                model.CoverImage = item.CoverImage;
            }

            _logger.LogInformation($"UpdateAnimal: {JsonConvert.SerializeObject(model)}");

            await _adminPanelServices.UpdateAnimal(model);

            return(RedirectToAction("AnimalDetails", "AdminPanel", new{ itemId = model?.Id }));
        }
예제 #2
0
        public async Task <IActionResult> UpdateAnimal(string itemId)
        {
            ViewBag.Categories = await _adminPanelServices.GetCategoryList();

            if (string.IsNullOrEmpty(itemId))
            {
                return(RedirectToAction("Index", "AdminPanel"));
            }
            var result = await _adminPanelServices.GetAnimalDetails(itemId);

            LiveAnimalViewModel liveAnimalViewModel = new LiveAnimalViewModel
            {
                Id            = result.Id,
                Title         = result.Title,
                TitleBn       = result.TitleBn,
                Category      = result.Category.Id,
                Color         = result.Color,
                Location      = result.Location,
                LocationBn    = result.LocationBn,
                Origin        = result.Origin,
                OriginBn      = result.OriginBn,
                Description   = result.Description,
                DescriptionBn = result.DescriptionBn,
                Price         = result.Price,
                Images        = result.Images,
                Height        = result.Height,
                Weight        = result.Weight,
                Teeth         = result.Teeth,
            };

            _logger.LogInformation($"AnimalInfo: {JsonConvert.SerializeObject(result)}");
            //ViewBag.Images = liveAnimalViewModel.Images;
            return(View(liveAnimalViewModel));
        }
예제 #3
0
        public async Task <bool> AddAnimal(LiveAnimalViewModel model)
        {
            try
            {
                var result = await BuildAnimal(model);

                await _repository.SaveAsync <LiveAnimal>(result);

                return(true);
            }
            catch (Exception e)
            {
                _logger.LogError(e, $"AddAnimal Failed: {e.Message}");
                return(false);
            }
        }
예제 #4
0
        private async Task <LiveAnimal> BuildAnimal(LiveAnimalViewModel model)
        {
            var category = await _repository.GetItemAsync <Category>(e => e.Id == model.Category);

            LiveAnimal liveAnimal = new LiveAnimal
            {
                Id            = model.Id,
                Title         = model.Title,
                TitleBn       = model.TitleBn,
                Category      = category,
                Color         = model.Color,
                Location      = model.Location,
                LocationBn    = model.LocationBn,
                Origin        = model.Origin,
                OriginBn      = model.OriginBn,
                Price         = model.Price,
                Description   = model.Description,
                DescriptionBn = model.DescriptionBn,
                Images        = model.Images,
                CoverImage    = model.CoverImage,
                Featured      = model.Featured,
                Weight        = model.Weight,
                Height        = model.Height,
                Teeth         = model.Teeth,
            };
            Dictionary <string, string> color = new Dictionary <string, string>
            {
                { "Black", "কালো" },
                { "White", "সাদা" },
                { "Red", "লাল" },
                { "Mixed", "মিশ্র" },
                { "Ash", "খাকি" }
            };

            liveAnimal.ColorBn = color[model.Color];
            return(liveAnimal);
        }
예제 #5
0
        public async Task <IActionResult> AddAnimal([Bind] LiveAnimalViewModel model, ICollection <IFormFile> files, IFormFile cover)
        {
            ViewBag.Categories = await _adminPanelServices.GetCategoryList();

            if (ModelState.IsValid == false)
            {
                return(View(model));
            }

            var id = Guid.NewGuid().ToString();

            model.Id = id;
            var coverImage = await _adminPanelServices.UploadCoverImage(cover);

            var images = await _adminPanelServices.UploadImage(files);

            model.Images     = images;
            model.CoverImage = coverImage;
            _logger.LogInformation($"AddAnimal: {JsonConvert.SerializeObject(model)}");

            await _adminPanelServices.AddAnimal(model);

            return(RedirectToAction("Index", "AdminPanel"));
        }