private readonly Window1 window1;
public Window2(Window1 window1)
{
InitializeComponent();
this.window1 = window1;
}
Window2 open = new Window2(this);
window1.Focus();
[Authorize]
public ActionResult Index()
{
...
}
[Authorize (Users="admin")]
public ActionResult Edit()
{
...
}
A DbContext instance represents a combination of the Unit Of Work and Repository patterns such that it can be used to query from a database and group together changes that will then be written back to the store as a unit.
public interface IEntity
{
int Id { get; set; }
}
public class Model : IEntity
{
public int Id { get; set; }
// ...
}
public static bool ExistById<T>(this DbSet<T> source, int id) where T : IEntity
{
return source.Count(c => c.Id == id) > 0;
}
public class User
{
public int Id {get;set;}
public string FirstName {get;set;}
public string SecondName {get;set;}
public DateTime DateOfBirth {get;set;}
public string Email {get;set;}
public string Password {get;set;}
public virtual Token Token { get; set; }
public int TokenId { get; set; }
}
public class College
{
public int? AccrLevel { get; set; }
public string Address { get; set; }
public virtual Area Area { get; set; }
public int AreaId { get; set; }
public bool? Demo { get; set; }
public virtual Director Director { get; set; }
public int DirectorId { get; set; }
public string Email { get; set; }
public bool? Full { get; set; }
[Key]
public int CollegeId { get; set; }
public string Locality { get; set; }
public virtual LocalityType LocalityType { get; set; }
public int LocalityTypeId { get; set; }
public string Name { get; set; }
public string Phone { get; set; }
public string Site { get; set; }
public virtual ICollection<Speciality> Specialities { get; set; }
public virtual Status Status { get; set; }
public int? StatusId { get; set; }
public virtual University University { get; set; }
public int? UniversityId { get; set; }
}
public class Speciality
{
public virtual ICollection<College> Colleges { get; set; }
[ForeignKey("DirectionCode")]
public virtual Direction Direction { get; set; }
public string DirectionCode { get; set; }
public string Name { get; set; }
[Key]
public string SpecialityCode { get; set; }
}
var list = new List<string>() { "one", "two", "three", "four" };
var expected = "two";
var result = list.Contains(expected);
// либо
result = list.Count(a => a == expected) > 0;
var regions = new List<string>() { "region 1", "region 2", "region 3", "region 4" };
repository.Colleges.Where(college => regions.Count(a => a == college.Area.Region.Name) > 0);
/*А нельзя ли просто объединить эти параметры в одну сущность, например так:
class Prox
{
public string[] Prox1 {get;set;}
public int[] Prox2 {get;set;}
}*/
var items = new List<KeyValuePair<string, string>>();
for (int i = 0; i < Prox.Length; i++)
{
items.Add(new KeyValuePair<string, string>(Prox[i], accitem[i]));
}
// с использованием Parallel, если массивы очень огромные
// Parallel.For(0, prox.Length, i => items.Add(new KeyValuePair<string, string>(Prox[i], accitem[i])));
Parallel.ForEach(items, options, p => indieroyale(p.Key, p.Value));
Parallel.For(0, Prox.Length, options, i => indieroyale(Prox[i], accitem[i]));
dataGrid.ItemsSource = dataFromMySql;
var timer = new System.Windows.Threading.DispatcherTimer();
timer.Tick += (oe,e)=> dataGrid.Items.Refresh();
/* или */
/* timer.Tick += (oe,e)=> { dataGrid.ItemsSource = null; dataGrid.ItemsSource = dataFromMySql; } */
timer.Interval = new TimeSpan(0,0,10);
timer.Start();
public class ErrorController
{
public virtual ActionResult BadRequest()
{
return View();
}
public virtual ActionResult Forbidden()
{
return View();
}
public virtual ActionResult Index()
{
return View();
}
public virtual ActionResult NotFound()
{
return View();
}
}
public class ExtHandleErrorAttribute : HandleErrorAttribute
{
//private readonly ILogger logger;
public ExtHandleErrorAttribute(/*ILogger logger*/)
{
//this.logger = logger;
}
public override void OnException(ExceptionContext filterContext)
{
if (filterContext.ExceptionHandled || !filterContext.HttpContext.IsCustomErrorEnabled)
{
return;
}
if (new HttpException(null, filterContext.Exception).GetHttpCode() != 500)
{
return;
}
if (!ExceptionType.IsInstanceOfType(filterContext.Exception))
{
return;
}
if (filterContext.HttpContext.Request.Headers["X-Requested-With"] == "XMLHttpRequest")
{
filterContext.Result = new JsonResult
{
JsonRequestBehavior = JsonRequestBehavior.AllowGet,
Data = new
{
error = true,
message = filterContext.Exception.Message
}
};
}
else
{
var controllerName = (string)filterContext.RouteData.Values["controller"];
var actionName = (string)filterContext.RouteData.Values["action"];
var model = new HandleErrorInfo(filterContext.Exception, controllerName, actionName);
filterContext.Result = new ViewResult
{
ViewName = View,
MasterName = Master,
ViewData = new ViewDataDictionary<HandleErrorInfo>(model),
TempData = filterContext.Controller.TempData
};
}
//var e = filterContext.Exception;
//logger.Error(e, e.Message);
filterContext.ExceptionHandled = true;
filterContext.HttpContext.Response.Clear();
filterContext.HttpContext.Response.StatusCode = 500;
filterContext.HttpContext.Response.TrySkipIisCustomErrors = true;
}
}
public class FilterConfig
{
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
var extHandleErrorAttribute = DependencyResolver.Current.GetService<ExtHandleErrorAttribute>();// new ExtHandleErrorAttribute();
filters.Add(extHandleErrorAttribute);
}
}
protected void Application_Error(object sender, EventArgs e)
{
var httpContext = ((MvcApplication)sender).Context;
var currentRouteData = RouteTable.Routes.GetRouteData(new HttpContextWrapper(httpContext));
var currentController = " ";
var currentAction = " ";
if (currentRouteData != null)
{
if (currentRouteData.Values["controller"] != null && !String.IsNullOrEmpty(currentRouteData.Values["controller"].ToString()))
{
currentController = currentRouteData.Values["controller"].ToString();
}
if (currentRouteData.Values["action"] != null && !String.IsNullOrEmpty(currentRouteData.Values["action"].ToString()))
{
currentAction = currentRouteData.Values["action"].ToString();
}
}
var ex = Server.GetLastError();
var controller = new ErrorController();
var routeData = new RouteData();
var action = "Index";
if (ex is HttpException)
{
var httpEx = ex as HttpException;
switch (httpEx.GetHttpCode())
{
case 404:
action = "NotFound";
break;
case 403:
action = "Forbidden";
break;
case 400:
action = "BadRequest";
break;
default:
action = "Index";
//var logger = DependencyResolver.Current.GetService<ILogger>();
//logger.Error(ex, ex.Message);
break;
}
}
httpContext.ClearError();
httpContext.Response.Clear();
httpContext.Response.StatusCode = ex is HttpException ? ((HttpException)ex).GetHttpCode() : 500;
httpContext.Response.TrySkipIisCustomErrors = true;
routeData.Values["controller"] = "Error";
routeData.Values["action"] = action;
controller.ViewData.Model = new HandleErrorInfo(ex, currentController, currentAction);
((IController)controller).Execute(new RequestContext(new HttpContextWrapper(httpContext), routeData));
}
<customErrors mode="On" />
<httpErrors>
<remove statusCode="400" subStatusCode="-1" />
<remove statusCode="403" subStatusCode="-1" />
<remove statusCode="502" subStatusCode="-1" />
<remove statusCode="501" subStatusCode="-1" />
<remove statusCode="500" subStatusCode="-1" />
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="400" prefixLanguageFilePath="" path="/Error/BadRequest" responseMode="ExecuteURL" />
<error statusCode="404" prefixLanguageFilePath="" path="/Error/NotFound" responseMode="ExecuteURL" />
<error statusCode="500" prefixLanguageFilePath="" path="/Error" responseMode="ExecuteURL" />
<error statusCode="501" prefixLanguageFilePath="" path="/Error" responseMode="ExecuteURL" />
<error statusCode="502" prefixLanguageFilePath="" path="/Error" responseMode="ExecuteURL" />
<error statusCode="403" prefixLanguageFilePath="" path="/Error/Forbidden" responseMode="ExecuteURL" />
</httpErrors>
public class Area // Район
{
public int Id { get; set; }
public string Name { get; set; }
public int RegionId { get; set; }
public virtual Region Region {get; set;}
public byte[] Map { get; set; }
}
public class Region // Область
{
public int Id { get; set; }
public string Name { get; set; }
public byte[] Map { get; set; }
}
public class Area // Район
{
[Key]
public int AreaId { get; set; }
public string Name { get; set; }
public int RegionId { get; set; }
[ForeignKey("RegionId")]
public virtual Region Region {get; set;}
public byte[] Map { get; set; }
}
public class Region // Область
{
[Key]
public int RegionId { get; set; }
public string Name { get; set; }
public byte[] Map { get; set; }
}