Lodhi Sohilkhan

Lodhi Sohilkhan

  • NA
  • 229
  • 5.9k

format Date in DirectController Linq

Mar 7 2019 5:27 AM
How to Apply Direct Controller formate Date in linq?
public ActionResult GenerateUgraniList(GenerateUgraniList gg, int Year, int Month)
{
DateTime first_date = new DateTime(Year, Month, 1);
DateTime last_date = new DateTime(Year, Month, DateTime.DaysInMonth(Year, Month));
var CustomerServicesData = (from cts in db.CustomerServices
join cus in db.Customers on cts.CustomerId equals cus.Id
join srv in db.ServiceMasters on cts.ServiceId equals srv.Id
where cts.ServiceId == gg.ServiceId
select new
{
CustomerId = cts.CustomerId,
ServiceId = cts.ServiceId,
CustomerName = cus.CustomerName,
ServiceName = srv.ServiceName,
ServicePrice = srv.Price,
}).ToList();
int i = 0;
foreach(var itm in CustomerServicesData)
{
GenerateUgraniList ob = new CollectionApp.GenerateUgraniList();
ob.FromDate = first_date;
ob.ToDate = last_date;
ob.Year = gg.Year;
ob.Month = gg.Month;
ob.CustomerId = itm.CustomerId;
ob.CustomerName = itm.CustomerName;
ob.ServiceId = itm.ServiceId;
ob.ServiceName = itm.ServiceName;
ob.ServicePrice = Convert.ToDecimal(itm.ServicePrice);
db.GenerateUgraniLists.Add(ob);
i = db.SaveChanges();
i = ob.Id;
}
if (i > 0)
{
R1.Status = 1;
R1.Message = "Ugrani List Generated Successfully.";
}
else
{
R1.Status = 0;
R1.Message = "Error.";
}
return Json(R1, JsonRequestBehavior.AllowGet);
}

Answers (2)