Пример #1
0
        // GET: Admin/Shopes/Edit/5
        public async Task <IActionResult> Edit(int?id)
        {
            var vm = new ShopeIM();

            if (id == null)
            {
                vm.Active     = true;
                vm.ToLeft     = 0;
                vm.ToTop      = 0;
                vm.Importance = 0;
            }
            else
            {
                var article = await _context.Shopes.FindAsync(id);

                if (article == null)
                {
                    return(NotFound());
                }

                vm = _mapper.Map <ShopeIM>(article);
            }


            return(View(vm));
        }
Пример #2
0
        public async Task <IActionResult> Edit(ShopeIM article)
        {
            if (!ModelState.IsValid)
            {
                AR.Setfailure(GetModelErrorMessage());
                return(Json(AR));
            }


            try
            {
                if (article.Id > 0)
                {
                    var model = await _context.Shopes.FirstOrDefaultAsync(d => d.Id == article.Id);

                    if (model == null)
                    {
                        AR.Setfailure(Messages.HttpNotFound);
                        return(Json(AR));
                    }
                    model = _mapper.Map(article, model);

                    model.UpdatedBy   = User.Identity.Name;
                    model.UpdatedDate = DateTime.Now;


                    _context.Entry(model).State = EntityState.Modified;
                    await _context.SaveChangesAsync();

                    AR.SetSuccess(string.Format(Messages.AlertUpdateSuccess, EntityNames.Shop));
                }
                else
                {
                    var model = _mapper.Map <Shope>(article);

                    model.CreatedBy   = User.Identity.Name;
                    model.CreatedDate = DateTime.Now;


                    //model.Body = WebUtility.HtmlEncode(page.Body);

                    _context.Add(model);
                    await _context.SaveChangesAsync();


                    AR.SetSuccess(string.Format(Messages.AlertCreateSuccess, EntityNames.Shop));
                }


                return(Json(AR));
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ShopeExists(article.Id))
                {
                    AR.Setfailure(Messages.HttpNotFound);
                    return(Json(AR));
                }
                else
                {
                    throw;
                }
            }
        }