Example #1
0
        // GET: Admin/Branches/Edit/5
        public async Task <IActionResult> Edit(int?id)
        {
            var vm = new BranchIM();

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

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

                vm = _mapper.Map <BranchIM>(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));
        }
Example #2
0
        public async Task <IActionResult> Edit(BranchIM 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.Branches.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.Branch));
                    pm.ObjectId = model.Id.ToString();
                }
                else
                {
                    var model = _mapper.Map <Branch>(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.Branch));
                }



                await CreatedUpdatedPageMetaAsync(_context, pm);

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