Esempio n. 1
0
        // GET: Admin/Exhibitions/Edit/5
        public async Task <IActionResult> Edit(int?id)
        {
            var vm = new ExhibitionIM();

            if (id == null)
            {
                vm.Active    = true;
                vm.DateStart = DateTime.Now;
                vm.DateEnd   = DateTime.Now;
            }
            else
            {
                var article = await _context.Exhibitions.FindAsync(id);

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

                vm = _mapper.Map <ExhibitionIM>(article);

                var pm = await _context.PageMetas.FirstOrDefaultAsync(d => d.ModuleType == (short)ModuleType.EXHIBITION && d.ObjectId == vm.Id.ToString());

                if (pm != null)
                {
                    vm.SEOTitle       = pm.Title;
                    vm.SEOKeywords    = pm.Keywords;
                    vm.SEODescription = pm.Description;
                }
            }


            return(View(vm));
        }
Esempio n. 2
0
        public async Task <IActionResult> Edit(ExhibitionIM article)
        {
            if (!ModelState.IsValid)
            {
                AR.Setfailure(GetModelErrorMessage());
                return(Json(AR));
            }


            try
            {
                var pm = new PageMeta
                {
                    Title       = article.SEOTitle,
                    Description = article.SEODescription,
                    Keywords    = article.SEOKeywords,
                    ModuleType  = (short)ModuleType.EXHIBITION
                };


                if (article.Id > 0)
                {
                    var model = await _context.Exhibitions.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.Exhibition));
                    pm.ObjectId = model.Id.ToString();
                }
                else
                {
                    var model = _mapper.Map <Exhibition>(article);

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


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

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

                    pm.ObjectId = model.Id.ToString();

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



                await CreatedUpdatedPageMetaAsync(_context, pm);

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