Ejemplo n.º 1
0
        public ActionResult Edit(Page page)
        {
            if(_pageRepository.InsertOrUpdate(page, _validation))
            {
                _unitOfWork.Save();
                return RedirectToAction("Index");
            }

            return View();
        }
Ejemplo n.º 2
0
 /// <summary>
 /// validate page
 /// </summary>
 /// <param name="page">page</param>
 /// <param name="validation">validation dictionary</param>
 private void ValidatePage(Page page, IValidationDictionary validation)
 {
     if (!SlugIsUnique(page.PageId, page.Slug))
         validation.AddError("Slug", "Slug is already in use.");
 }
Ejemplo n.º 3
0
        /// <summary>
        /// insert or update page
        /// </summary>
        /// <param name="page">page</param>
        /// <param name="validation">validation dictionary</param>
        /// <returns>success</returns>
        public bool InsertOrUpdate(Page page, IValidationDictionary validation)
        {
            ValidatePage(page, validation);

            if (validation.IsValid)
            {
                if (page.PageId == default(int))
                {
                    // New entity
                    _context.Pages.Add(page);
                }
                else
                {
                    // Existing entity
                    _context.Entry(page).State = EntityState.Modified;
                }

                return true;
            }

            return false;
        }