예제 #1
0
        public IActionResult Edit(int id, PrivatePromotion privatePromotion)
        {
            if (id != privatePromotion.Id)
            {
                return(NotFound());
            }
            foreach (var modelState in ViewData.ModelState.Values)
            {
                foreach (var error in modelState.Errors)
                {
                    //DoSomethingWith(error);
                }
            }
            if (ModelState.IsValid)
            {
                try
                {
                    _privatePromotionRepository.UpdatePrivatePromotion(privatePromotion);
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!_privatePromotionRepository.PrivatePromotionExists(privatePromotion.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }

            return(View(privatePromotion));
        }
예제 #2
0
        public void AddPrivatePromotion(PrivatePromotion privatePromotion)
        {
            if (privatePromotion.Photos != null)
            {
                privatePromotion.Photos = privatePromotion.Photos.Where(p => !p.IsDeleted).ToList();
            }

            _appDbContext.PrivatePromotions.Add(privatePromotion);
            _appDbContext.SaveChanges();
        }
예제 #3
0
        public IActionResult Create(PrivatePromotion privatePromotion)
        {
            if (ModelState.IsValid)
            {
                _privatePromotionRepository.AddPrivatePromotion(privatePromotion);
                return(RedirectToAction(nameof(Index)));
            }

            return(View(privatePromotion));
        }
예제 #4
0
        public void UpdatePrivatePromotion(PrivatePromotion privatePromotion)
        {
            if (privatePromotion.Photos != null)
            {
                foreach (var photoModel in privatePromotion.Photos)
                {
                    if (photoModel.Id != 0)
                    {
                        var ppPhoto = _appDbContext.PrivatePromotionPhotos.Find(photoModel.Id);
                        _appDbContext.Entry(ppPhoto).State = EntityState.Detached;
                        //deleted
                        if (photoModel.IsDeleted)
                        {
                            _appDbContext.PrivatePromotionPhotos.Remove(ppPhoto);
                        }
                        else
                        {
                            ppPhoto.IsPrimary = photoModel.IsPrimary;
                            _appDbContext.Update(ppPhoto);
                        }
                    }
                    else
                    {
                        if (!photoModel.IsDeleted)
                        {
                            photoModel.PrivatePromotionId = privatePromotion.Id;
                            _appDbContext.PrivatePromotionPhotos.Add(photoModel);
                        }
                    }
                }
            }

            _appDbContext.Entry(privatePromotion).State = EntityState.Modified;
            _appDbContext.Update(privatePromotion);
            _appDbContext.SaveChanges();
        }