protected override ValidationResult IsValid(object value, ValidationContext validationContext) { Campaign campaign = validationContext.ObjectInstance as Campaign; if (value != null && campaign != null) { switch (validationContext.MemberName) { // ///Sprawdzenie czy data rozpoczęcia jest wcześniejsza od daty zakończenia //case "StartDate": // DateTime startDate = (DateTime)value; // if (startDate > campaign.EndDate) // { // return new ValidationResult("Data rozpoczęcia musi być wcześniejsza od daty zakończenia.", new string[] { validationContext.MemberName, "StartDate" }); // } // break; // ///Sprawdzenie czy data zakończenia jest późniejsza niż data rozpoczęcia //case "EndDate": // DateTime endDate = (DateTime)value; // if (endDate < campaign.StartDate) // { // return new ValidationResult("Data zakończenia musi być późniejsza od daty rozpoczęcia.", new string[] { validationContext.MemberName, "EndDate" }); // } // break; // Sprawdzenie unikalności nazwy case "Name": var name = (string)value; if (name != null && name.Length > 0) { using (var Context = new AdServContext()) { if (Context.Campaigns.Count(c => c.Name == name && c.Id != campaign.Id) > 0) { return(new ValidationResult("Kampania o podanej nazwie już istnieje.", new string[] { validationContext.MemberName })); } } } break; } } return(ValidationResult.Success); }
protected override ValidationResult IsValid(object value, ValidationContext validationContext) { var category = validationContext.ObjectInstance as Category; if (value != null && category != null) { switch (validationContext.MemberName) { // Sprawdzenie unikalności nazwy case "Name": var name = (string)value; if (name != null && name.Length > 0) { using (var Context = new AdServContext()) { if (Context.Categories.Count(c => c.Name == name && c.Id != category.Id) > 0) { return(new ValidationResult("Kategoria o podanej nazwie już istnieje.", new string[] { validationContext.MemberName })); } } } break; // Sprawdzenie unikalności kodu case "Code": string code = (string)value; if (code != null && code.Length > 0) { using (AdServContext Context = new AdServContext()) { if (Context.Categories.Count(c => c.Code == code && c.Id != category.Id) > 0) { return(new ValidationResult("Kategoria o podanym kodzie już istnieje.", new string[] { validationContext.MemberName })); } } } break; } } return(ValidationResult.Success); }
public EFBaseRepository() { Context = new AdServContext(); }
public ActionResult Index(string data0, string data1, string data2, string data3, int Id, string viewId) { var errors = new List <string>(); var nameCookie = "AdServer" + viewId; try { var selectionRequest = new MultimediaObjectSelection.MultimediaObjectsSelectionParams { ID = Id, Data0 = data0, Data1 = data1, Data2 = data2, Data3 = data3, RequestDate = DateTime.Now, RequestSource = (int)Statistic.RequestSourceType.WWW }; var ips = Request.ServerVariables["HTTP_X_FORWARDED_FOR"]; selectionRequest.RequestIP = !string.IsNullOrEmpty(ips) ? ips.Split(',')[0] : Request.ServerVariables["REMOTE_ADDR"]; var sessionId = Request.Cookies.Get(nameCookie) == null?Guid.NewGuid().ToString() : Request.Cookies[nameCookie]["sessionId"]; selectionRequest.SessionId = sessionId; var cookie = new HttpCookie(nameCookie); cookie.Values.Add("sessionId", sessionId); using (var ctx = new AdServContext()) { var repositories = EFRepositorySet.CreateRepositorySet(ctx); try { var mos = new MultimediaObjectSelection(repositories); List <string> err = new List <string>(); const string key = "FILESTREAM_OPTION"; var urlKey = ConfigurationManager.AppSettings[key]; bool filestreamOption = false; if (urlKey != null && !string.IsNullOrEmpty(urlKey)) { bool.TryParse(urlKey, out filestreamOption); } bool add = true; if (Request.UrlReferrer != null) { if (Request.Url.Host == Request.UrlReferrer.Host) { add = false; } } AdFile response = mos.GetMultimediaObject(selectionRequest, filestreamOption, add, out err); cookie.Values.Add("cmp", response.CmpId.ToString()); if (err != null && err.Count > 0) { errors.AddRange(err); } else { cookie.Values.Add("Id", response.ID.ToString()); cookie.Values.Add("StatusCode", response.StatusCode.ToString()); Response.AppendCookie(cookie); return(File(response.Contents, response.MimeType)); } } catch (Exception ex) { var hierarchy = new List <Exception>(); ExceptionsHandlingHelper.HierarchizeError(ex, ref hierarchy); if (hierarchy.Count > 0) { errors.AddRange(hierarchy.Select(s => s.Message + Environment.NewLine + s.StackTrace).Distinct().AsEnumerable()); } SaveErrorInLogFile(selectionRequest, ex); } } } catch (Exception ex) { var hierarchy = new List <Exception>(); ExceptionsHandlingHelper.HierarchizeError(ex, ref hierarchy); if (hierarchy.Count > 0) { errors.AddRange(hierarchy.Select(s => s.Message + Environment.NewLine + s.StackTrace).Distinct().AsEnumerable()); } SaveErrorInLogFile(ex); } return(null); }
private void StaticClicked(GetMultimediaObject_Request request, int id, int statusCode) { var errors = new List <string>(); var hierarchy = new List <Exception>(); try { if (request != null) { var selectionRequest = new MultimediaObjectSelection.MultimediaObjectsSelectionParams { Data0 = request.Data0, Data1 = request.Data1, Data2 = request.Data2, Data3 = request.Data3, ID = id, RequestDate = DateTime.Now, SessionId = request.SessionId, RequestSource = (int) (System.Web.HttpContext.Current.Request.UserAgent == null ? Statistic.RequestSourceType.Desktop : Statistic.RequestSourceType.WWW), RequestIP = HttpContext.Current.Request.UserHostAddress }; using (var ctx = new AdServContext()) { var repositories = EFRepositorySet.CreateRepositorySet(ctx); try { var mos = new MultimediaObjectSelection(repositories); const string key = "FILESTREAM_OPTION"; var urlKey = ConfigurationManager.AppSettings[key]; if (urlKey != null && !string.IsNullOrEmpty(urlKey)) { bool filestreamOption; bool.TryParse(urlKey, out filestreamOption); } mos.SaveStatisticsEntry(selectionRequest, new AdFile { ID = id, StatusCode = statusCode }, true); } catch (Exception ex) { ExceptionsHandlingHelper.HierarchizeError(ex, ref hierarchy); if (hierarchy.Count > 0) { errors.AddRange(hierarchy.Select(s => s.Message + Environment.NewLine + s.StackTrace).Distinct().AsEnumerable()); } SaveErrorInLogFile(selectionRequest, ex); } } } else { errors.Add("Parametr requesta nie może być nullem."); } } catch (Exception ex) { ExceptionsHandlingHelper.HierarchizeError(ex, ref hierarchy); if (hierarchy.Count > 0) { errors.AddRange(hierarchy.Select(s => s.Message + Environment.NewLine + s.StackTrace).Distinct().AsEnumerable()); } SaveErrorInLogFile(ex); } }