using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Petrol_Bunk.Models;
namespace Petrol_Bunk.Areas.Admin.Controllers
{
    public class HomeController : Controller
    {
        // GET: Admin/Home/Index
        public ActionResult Index()
        {
            Petrol_BunkEntities ctx = new Petrol_BunkEntities();
            var getdata = ctx.TblCompanies.Where(x => x.CmpId == 1).FirstOrDefault();
            ViewBag.CmpMsg = TempData["CmpMsg"] == null ? "" : TempData["CmpMsg"] as string;

            return View(getdata);
        }
        public ActionResult Company_post(TblCompany obj)
        {
            Petrol_BunkEntities ctx = new Petrol_BunkEntities();
            var getdata = ctx.TblCompanies.Where(x => x.CmpId == obj.CmpId).FirstOrDefault();
            if (getdata != null)
            {
                getdata.Address = obj.Address;
                getdata.Mob = obj.Mob;
                getdata.GSTNo = obj.GSTNo;
                getdata.CmpName = obj.CmpName;
                ctx.Entry(getdata).State = System.Data.Entity.EntityState.Modified;
                if (ctx.SaveChanges() > 0)
                {
                    TempData["CmpMsg"] = "Updated Company Details";
                }
                else
                {
                    TempData["CmpMsg"] = "Try Again";
                }
            }
            return new RedirectResult("/Admin/Home");
        }
    }
}