using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using FormsGenerated.Models.Entities;
using FormsGenerated.Models;

namespace FormsGenerated.Controllers
{ 
    public class Default1Controller : Controller
    {
        private FormsGeneratedContext db = new FormsGeneratedContext();

        //
        // GET: /Default1/

        public ViewResult Index()
        {
            return View(db.Osobas.ToList());
        }

        //
        // GET: /Default1/Details/5

        public ViewResult Details(int id)
        {
            Osoba osoba = db.Osobas.Find(id);
            return View(osoba);
        }

        //
        // GET: /Default1/Create

        public ActionResult Create()
        {
            return View();
        } 

        //
        // POST: /Default1/Create

        [HttpPost]
        public ActionResult Create(Osoba osoba)
        {
            if (ModelState.IsValid)
            {
                db.Osobas.Add(osoba);
                db.SaveChanges();
                return RedirectToAction("Index");  
            }

            return View(osoba);
        }
        
        //
        // GET: /Default1/Edit/5
 
        public ActionResult Edit(int id)
        {
            Osoba osoba = db.Osobas.Find(id);
            return View(osoba);
        }

        //
        // POST: /Default1/Edit/5

        [HttpPost]
        public ActionResult Edit(Osoba osoba)
        {
            if (ModelState.IsValid)
            {
                db.Entry(osoba).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            return View(osoba);
        }

        //
        // GET: /Default1/Delete/5
 
        public ActionResult Delete(int id)
        {
            Osoba osoba = db.Osobas.Find(id);
            return View(osoba);
        }

        //
        // POST: /Default1/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(int id)
        {            
            Osoba osoba = db.Osobas.Find(id);
            db.Osobas.Remove(osoba);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

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