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 PaymentController : Controller
    {
        // GET: Admin/Payment/DigitalPayment
        string status = "";
        public ActionResult DigitalPayment()
        {
            ViewBag.PaidMsg = TempData["PaidMsg"] == null ? "" : TempData["PaidMsg"] as string;

            return View();
        }
        public JsonResult TodayPrice(string Fuel = "")
        {
            Petrol_BunkEntities ctx = new Petrol_BunkEntities();
            DateTime dt = DateTime.Now.Date;
            if (Fuel == "Petrol")
            {

                var getList = ctx.TblMachineReadings.Where(x => x.MachineId == 1
                && x.ReadingDate.Value.Day == dt.Day
                && x.ReadingDate.Value.Month == dt.Month
                && x.ReadingDate.Value.Year == dt.Year).FirstOrDefault();

                if (getList != null)
                {
                    status = getList.Price.ToString();
                }
                else
                {
                    status = "Open Reading has not set";
                }
            }
            else
            {
                var getList = ctx.TblMachineReadings.Where(x => x.MachineId == 3
               && x.ReadingDate.Value.Day == dt.Day
               && x.ReadingDate.Value.Month == dt.Month
               && x.ReadingDate.Value.Year == dt.Year).FirstOrDefault();

                if (getList != null)
                {
                    status = getList.Price.ToString();
                }
                else
                {
                    status = "Open Reading has not set";
                }
            }
            return Json(status, JsonRequestBehavior.AllowGet);
        }
        public ActionResult DigitalPayment_Post(TblCreadit obj)
        {
            Petrol_BunkEntities ctx = new Petrol_BunkEntities();
            obj.RowStatus = 0;
            obj.InsertedDate = DateTime.Now;
            obj.PaidDate = DateTime.Now;
            obj.CustomerId = 0;
            //obj.PaidDate = DateTime.Now;
            obj.Type = "Digital";
            
            ctx.TblCreadits.Add(obj);
            if (ctx.SaveChanges() > 0)
            {
                TempData["PaidMsg"] = "Payment Recieved";
            }
            else
            {
                TempData["PaidMsg"] = "Try Again";
            }
            return new RedirectResult("/Admin/Payment/DigitalPayment");
        }
    }
}