public ActionResult HideAllFood()
{
var foods = _canteenService.GetCanteenFoods();
foreach (var food in foods)
{
if (!food.Block)
{
var menu = _canteenService.GetCanteenMenubyId(food.MenuID);
if (menu.StatusID != 2)
{
food.StatusID = 3;
_canteenService.UpdateCanteenFood(food);
}
}
}
return Json(new {success = true});
}
public class TimerModule : IHttpModule
{
static System.Threading.Timer timer;
long interval = 30000; //30 секунд
static object synclock = new object();
static bool sent = false;
public void Init(HttpApplication app)
{
timer = new System.Threading.Timer(new TimerCallback(HideallFood), null, 0, interval);
}
private void HideallFood(object obj)
{
lock (synclock)
{
DateTime dd = DateTime.Now;
if (dd.Hour == 14 && dd.Minute == 1 && sent == false)
{
var foods = _canteenService.GetCanteenFoods();
foreach (var food in foods)
{
if (!food.Block)
{
var menu = _canteenService.GetCanteenMenubyId(food.MenuID);
if (menu.StatusID != 2)
{
food.StatusID = 3;
_canteenService.UpdateCanteenFood(food);
}
}
}
sent = true;
}
else if (dd.Hour != 14 && dd.Minute != 1)
{
sent = false;
}
}
}
public void Dispose()
{ }
}
public class SystemVariable : BaseEntity
{
public string Name { get; set; }
public string Type { get; set; }
public string Value { get; set; }
}
public ActionResult Menu()
{
var var = _systemService.GetSystemVariableByName("DateMenuUpdate");
if (var != null)
{
var type = Type.GetType(var.Type);
var menuUpdate = (DateTime)Convert.ChangeType(var.Value, type);
var dayCount = DateTime.Now.DayOfWeek == DayOfWeek.Monday ? -3 : -1;
if (DateTime.Now.DayOfWeek != DayOfWeek.Saturday && DateTime.Now.DayOfWeek != DayOfWeek.Sunday &&
(menuUpdate.Day != DateTime.Now.Day && DateTime.Now.Hour >= 14) || (menuUpdate.Day < DateTime.Now.AddDays(dayCount).Day) && DateTime.Now.Hour < 14)
{
var.Value = DateTime.Now.ToString();
var foods = _canteenService.GetCanteenFoods();
foreach (var food in foods)
{
if (!food.Block)
{
var menu = _canteenService.GetCanteenMenubyId(food.MenuID);
if (menu.StatusID != 2)
{
food.StatusID = 3;
_canteenService.UpdateCanteenFood(food);
}
}
}
_systemService.UpdateSystemVariable(var);
}
}
return View();
}
public class TimerModule : IHttpModule
{
static Timer timer;
long interval = 30000; //30 сек
static object synclock = new object();
static bool sent = false;
public void Init(HttpApplication app)
{
timer = new Timer(new TimerCallback(SendEmail), null, 0, interval);
}
private void SendEmail(object obj)
{
lock (synclock)
{
DateTime dd = DateTime.Now;
if (dd.Hour == 12 && dd.Minute == 13 && sent == false)
{
//что то делаем
sent = true;
}
else if (dd.Hour != 12 && dd.Minute != 13)
{
sent = false;
}
}
}
public void Dispose()
{ }
}