using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.Mvc;
using RedSocial.Models;

namespace RedSocial.Controllers
{
    public class SexesController : Controller
    {
        private Entities db = new Entities();

        /******************** USER ********************/


        /******************** ADMIN ********************/

        // GET: Sexes
        [Authorize(Roles = GlobalConstants.RoleAdmin)]
        public ActionResult Index()
        {
            return View(db.Sexes.ToList());
        }

        // GET: Sexes/Details/5
        //[Authorize(Roles = GlobalConstants.RoleAdmin)]
        //public ActionResult Details(int? id)
        //{
        //    if (id == null)
        //    {
        //        return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
        //    }
        //    Sex sex = db.Sexes.Find(id);
        //    if (sex == null)
        //    {
        //        return HttpNotFound();
        //    }
        //    return View(sex);
        //}

        // GET: Sexes/Create
        [Authorize(Roles = GlobalConstants.RoleAdmin)]
        public ActionResult Create()
        {
            return View();
        }

        // POST: Sexes/Create
        // Para protegerse de ataques de publicación excesiva, habilite las propiedades específicas a las que desea enlazarse. Para obtener 
        // más información vea http://go.microsoft.com/fwlink/?LinkId=317598.
        [HttpPost]
        [ValidateAntiForgeryToken]
        [Authorize(Roles = GlobalConstants.RoleAdmin)]
        public ActionResult Create([Bind(Include = "Id,Name")] Sex sex)
        {
            if (ModelState.IsValid)
            {
                db.Sexes.Add(sex);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(sex);
        }

        // GET: Sexes/Edit/5
        [Authorize(Roles = GlobalConstants.RoleAdmin)]
        public ActionResult Edit(int? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            Sex sex = db.Sexes.Find(id);
            if (sex == null)
            {
                return HttpNotFound();
            }
            return View(sex);
        }

        // POST: Sexes/Edit/5
        // Para protegerse de ataques de publicación excesiva, habilite las propiedades específicas a las que desea enlazarse. Para obtener 
        // más información vea http://go.microsoft.com/fwlink/?LinkId=317598.
        [HttpPost]
        [ValidateAntiForgeryToken]
        [Authorize(Roles = GlobalConstants.RoleAdmin)]
        public ActionResult Edit([Bind(Include = "Id,Name")] Sex sex)
        {
            if (ModelState.IsValid)
            {
                db.Entry(sex).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            return View(sex);
        }

        // GET: Sexes/Delete/5
        [Authorize(Roles = GlobalConstants.RoleAdmin)]
        public ActionResult Delete(int? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            Sex sex = db.Sexes.Find(id);
            if (sex == null)
            {
                return HttpNotFound();
            }
            return View(sex);
        }

        // POST: Sexes/Delete/5
        [HttpPost, ActionName("Delete")]
        [ValidateAntiForgeryToken]
        [Authorize(Roles = GlobalConstants.RoleAdmin)]
        public ActionResult DeleteConfirmed(int id)
        {
            Sex sex = db.Sexes.Find(id);
            db.Sexes.Remove(sex);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                db.Dispose();
            }
            base.Dispose(disposing);
        }
    }
}
