예제 #1
0
        public async Task <IActionResult> Edit(int id, CategoryViewModel category)
        {
            if (id != category.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    var    Category = _context.Categories.AsNoTracking().FirstOrDefault(c => c.Id == id);
                    string ImgUrl   = Category.ImgUrl;
                    Category = mapper.Map <Category>(category);

                    Category.ImgUrl = uploadImages.UpdateImage(ImgUrl, category.File);

                    _context.Update(Category);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CategoryExists(category.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(category));
        }
예제 #2
0
        public async Task <IActionResult> Edit(int id, MemberViewModel member)
        {
            if (id != member.Id)
            {
                return(NotFound());
            }
            member.ItemsCount = 0;
            var Member = _context.Members.AsNoTracking().FirstOrDefault(m => m.Id == member.Id);

            member.Password        = Member.Password;
            member.ConfirmPassword = Member.Password;
            if (ModelState.IsValid)
            {
                try
                {
                    member.ActivationCode = Member.ActivationCode;
                    string ImgUrl = Member.ImgUrl;

                    Member        = mapper.Map <Member>(member);
                    Member.ImgUrl = uploadImages.UpdateImage(ImgUrl, member.File);

                    _context.Update(Member);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!MemberExists(member.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CityId"] = new SelectList(_context.Cities, "Id", "Name", member.CityId);
            return(View(member));
        }
예제 #3
0
        public async Task <IActionResult> Edit(int id, ItemViewModel item)
        {
            if (id != item.Id)
            {
                return(NotFound());
            }

            try
            {
                if (ModelState.IsValid)
                {
                    try
                    {
                        var Item = _context.Items.AsNoTracking().FirstOrDefault(i => i.Id == id);

                        item.ClicksCount   = Item.ClicksCount;
                        item.ViewsCount    = Item.ViewsCount;
                        item.FavoriteCount = Item.FavoriteCount;
                        item.MembersCount  = item.MembersCount;
                        item.RatingCount   = item.RatingCount;
                        item.RatingValues  = item.RatingValues;
                        item.ShortLink     = Item.ShortLink;
                        item.Sorting       = Item.Sorting;
                        item.Date          = Item.Date;
                        string ImgUrl = Item.ImgUrl;
                        item.RatingValues = Item.RatingValues;
                        item.RatingCount  = Item.RatingCount;

                        Item        = mapper.Map <Item>(item);
                        Item.ImgUrl = uploadImages.UpdateImage(ImgUrl, item.File);

                        if (Item.RatingValues == null)
                        {
                            Item.RatingValues = 0;
                        }
                        if (Item.RatingCount == null)
                        {
                            Item.RatingCount = 0;
                        }

                        if (item.RaitingValue != 0)
                        {
                            Item.RatingCount++;
                            Item.RatingValues += item.RaitingValue;
                        }

                        _context.Update(Item);
                        await _context.SaveChangesAsync();
                    }
                    catch (DbUpdateConcurrencyException)
                    {
                        if (!ItemExists(item.Id))
                        {
                            return(NotFound());
                        }
                        else
                        {
                            throw;
                        }
                    }

                    return(RedirectToAction(nameof(Index)));
                }
                ViewData["CityId"]   = new SelectList(_context.Cities, "Id", "Name", item.CityId);
                ViewData["MemberId"] = new SelectList(supliers(), "Id", "FullName", item.MemberId);
                ViewData["UnitId"]   = new SelectList(units(), "Id", "Name");

                return(View(item));
            }
            catch
            {
                return(RedirectToAction(nameof(Index)));
            }
        }