//UpdateEventForm public object UpdateEventForm(string evnt, ModelStateDictionary ModelState) { try { JavaScriptSerializer serializer = new JavaScriptSerializer(); EventForm e = serializer.Deserialize <EventForm>(evnt); e.Validate(ModelState); if (e.DateEnd.CompareTo(DateTime.Now) <= 0 && AppHelper.CurrentUser.IsAdmin) { return(new JsonExecuteResult(JsonExecuteResultTypes.ERROR, "You can't update this event.")); } if (ModelState.IsValid) { if (!UpdateEvent(e)) { return(new JsonExecuteResult(JsonExecuteResultTypes.ERROR, "The event's information wasn't saved.")); } } else { ModelState.Remove("evnt"); var errors = (from M in ModelState select new { field = M.Key, message = M.Value.Errors.FirstOrDefault().ErrorMessage }).ToArray(); return(new JsonExecuteResult(JsonExecuteResultTypes.ERROR, "Please correct the errors and try again.", errors)); } } catch (Exception ex) { return(new JsonExecuteResult(JsonExecuteResultTypes.ERROR, ex.Message)); } return(new JsonExecuteResult(JsonExecuteResultTypes.SUCCESS)); }
//UpdateEvent public bool UpdateEvent(EventForm info) { Event evnt = (info.ID > 0) ? GetEvent(info.ID) : null; bool newEvent = evnt == null; bool iscurrent = !newEvent && GetCurrentEvent().ID == info.ID; try { using (TransactionScope ts = new TransactionScope()) { if (newEvent) { evnt = new Event(); dataContext.Events.InsertOnSubmit(evnt); } evnt.BuyerFee = info.BuyerFee; evnt.DateEnd = info.DateEnd; evnt.DateStart = info.DateStart; evnt.Description = info.Description; evnt.IsClickable = info.IsClickable; evnt.IsCurrent = info.IsCurrent; evnt.IsViewable = info.IsViewable; evnt.LastUpdate = DateTime.Now; evnt.Ordinary = info.Ordinary; evnt.Title = info.Title; evnt.Type_ID = info.Type_ID; if (newEvent) { GeneralRepository.SubmitChanges(dataContext); } if (evnt.EventCategories.Count > 0 && !newEvent) { foreach (EventCategory ec in evnt.EventCategories) { ec.IsActive = false; } } CategoriesMap cat_map; foreach (long index in info.CategoriesList) { cat_map = dataContext.CategoriesMaps.SingleOrDefault(CM => CM.ID == index); if (cat_map != null) { AddCategoryChildToEventCategory(evnt, cat_map); } } GeneralRepository.SubmitChanges(dataContext); if (!newEvent && evnt.CloseStep == 0) { dataContext.sp_Event_ChangeAuctionStartEnd(evnt.ID); } ts.Complete(); } } catch (ChangeConflictException cce) { Logger.LogException(cce); throw cce; } catch (Exception ex) { Logger.LogException(ex); throw ex; } if (iscurrent || GetCurrentEvent().ID == evnt.ID) { try { System.Net.WebClient client = new System.Net.WebClient(); client.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)"); client.OpenRead(Consts.CacheClearFrontendIP + Consts.FrontEndClearMethod); } catch (Exception ex) { Logger.LogException("[" + Consts.CacheClearFrontendIP + Consts.FrontEndClearMethod + "]", ex); } } return(true); }
//UpdateEvent public bool UpdateEvent(EventForm info) { Event evnt = (info.ID > 0) ? GetEvent(info.ID) : null; bool newEvent = evnt == null; bool iscurrent = !newEvent && GetCurrentEvent().ID == info.ID; try { using (TransactionScope ts = new TransactionScope()) { if (newEvent) { evnt = new Event(); dataContext.Events.InsertOnSubmit(evnt); } evnt.BuyerFee = info.BuyerFee; evnt.DateEnd = info.DateEnd; evnt.DateStart = info.DateStart; evnt.Description = info.Description; evnt.IsClickable = info.IsClickable; evnt.IsCurrent = info.IsCurrent; evnt.IsViewable = info.IsViewable; evnt.LastUpdate = DateTime.Now; evnt.Ordinary = info.Ordinary; evnt.Title = info.Title; evnt.Type_ID = info.Type_ID; if (newEvent) GeneralRepository.SubmitChanges(dataContext); if (evnt.EventCategories.Count > 0 && !newEvent) foreach (EventCategory ec in evnt.EventCategories) ec.IsActive = false; CategoriesMap cat_map; foreach (long index in info.CategoriesList) { cat_map = dataContext.CategoriesMaps.SingleOrDefault(CM => CM.ID == index); if (cat_map != null) AddCategoryChildToEventCategory(evnt, cat_map); } GeneralRepository.SubmitChanges(dataContext); if (!newEvent && evnt.CloseStep == 0) dataContext.sp_Event_ChangeAuctionStartEnd(evnt.ID); ts.Complete(); } } catch (ChangeConflictException cce) { Logger.LogException(cce); throw cce; } catch (Exception ex) { Logger.LogException(ex); throw ex; } if (iscurrent || GetCurrentEvent().ID == evnt.ID) { try { System.Net.WebClient client = new System.Net.WebClient(); client.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)"); client.OpenRead(Consts.CacheClearFrontendIP + Consts.FrontEndClearMethod); } catch (Exception ex) { Logger.LogException("[" + Consts.CacheClearFrontendIP + Consts.FrontEndClearMethod + "]", ex); } } return true; }