示例#1
0
        // GET: Admin/SocialApps/Edit/5
        public async Task <IActionResult> Edit(int?id)
        {
            var vm = new SocialAppIM();

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

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

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


            return(View(vm));
        }
示例#2
0
        public async Task <IActionResult> Edit(SocialAppIM article)
        {
            if (!ModelState.IsValid)
            {
                AR.Setfailure(GetModelErrorMessage());
                return(Json(AR));
            }


            try
            {
                if (article.Id > 0)
                {
                    var model = await _context.SocialApps.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.SocialApp));
                }
                else
                {
                    var model = _mapper.Map <SocialApp>(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.SocialApp));
                }
                _cacheService.Invalidate("SOCIALAPP");

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