public async Task <ActionResult> TableRoles(Ctrl_Table.Cl_Params <Cl_Role> a_Grid) { if (a_Grid != null) { ActionResult result = await a_Grid.f_Execute(m_AppDbContext, m_RoleManager.Roles); return(result); } return(new EmptyResult()); }
public async Task <ActionResult> TableSessions(Ctrl_Table.Cl_Params <Cl_Session> a_Grid) { if (a_Grid != null) { Cl_Seat[] seats = null; if (a_Grid.p_Action == Ctrl_Table.E_Actions.Edit) { seats = m_AppDbContext.p_Seats.Where(s => s.p_SessionID == a_Grid.p_Object.p_ID).ToArray(); if (seats.Any(s => s.p_TypeEmployment == Cl_Seat.E_TypeEmployment.Purchased)) { throw new Cl_UserException("Нельзя изменить концерт, имеющий хотябы один проданный билет"); } } var session = m_AppDbContext.p_Sessions.Include(s => s.p_Hall); ActionResult result = await a_Grid.f_Execute(m_AppDbContext, session); if (User.IsInRole("admin") && a_Grid.p_Action == Ctrl_Table.E_Actions.Add || a_Grid.p_Action == Ctrl_Table.E_Actions.Edit) { Cl_Hall hall = await m_AppDbContext.p_Halls.FirstOrDefaultAsync(h => h.p_ID == a_Grid.p_Object.p_HallID); if (hall != null) { a_Grid.p_Object.p_Hall = hall; if (a_Grid.p_Action == Ctrl_Table.E_Actions.Add) { foreach (Cl_Seat.E_Type type in Enum.GetValues(typeof(Cl_Seat.E_Type))) { f_SetSeatsForNewHall(a_Grid.p_Object, type); } } else if (a_Grid.p_Action == Ctrl_Table.E_Actions.Edit) { for (int i = 0; i < seats.Length; i++) { if (seats[i].p_TypeEmployment == Cl_Seat.E_TypeEmployment.Free) { seats[i].p_Price = a_Grid.p_Object.f_GetPrice(seats[i].p_Type); } } } await m_AppDbContext.SaveChangesAsync(); } else { throw new Exception("Не найден зал"); } } return(result); } return(new EmptyResult()); }
public async Task <ActionResult> TablePromoCodes(Ctrl_Table.Cl_Params <Cl_PromoCode> a_Grid) { if (a_Grid != null) { if (a_Grid.p_Action == Ctrl_Table.E_Actions.Edit || a_Grid.p_Action == Ctrl_Table.E_Actions.Add) { if (a_Grid.p_Object.p_DateStart > a_Grid.p_Object.p_DateEnd) { throw new Exception("Дата начало действия промо-кода больше его завершения"); } } return(await a_Grid.f_Execute(m_AppDbContext, m_AppDbContext.p_PromoCodes)); } return(new EmptyResult()); }
public async Task <ActionResult> TableHalls(Ctrl_Table.Cl_Params <Cl_Hall> a_Grid) { if (a_Grid != null) { if (a_Grid.p_Action == Ctrl_Table.E_Actions.Edit) { if (m_AppDbContext.p_Sessions.Any(s => s.p_HallID == a_Grid.p_Object.p_ID)) { throw new Exception("Нельзя изменить зал, имеющий хотябы один концерт"); } } return(await a_Grid.f_Execute(m_AppDbContext, m_AppDbContext.p_Halls)); } return(new EmptyResult()); }
public async Task <ActionResult> TableLogsHalls(Ctrl_Table.Cl_Params <Cl_LogsHalls> a_Grid) { if (a_Grid != null && a_Grid.p_Action == Ctrl_Table.E_Actions.Read) { DateTime dateStart = DateTime.Now.AddDays(-7); DateTime dateEnd = DateTime.Now; if (Request.Cookies["m_LogsDateStart"] != null) { DateTime.TryParse(Request.Cookies["m_LogsDateStart"], out dateStart); } if (Request.Cookies["m_LogsDateEnd"] != null) { DateTime.TryParse(Request.Cookies["m_LogsDateEnd"], out dateEnd); } dateStart = dateStart.Date; dateEnd = dateEnd.AddDays(1).Date; IQueryable <Cl_LogsHalls> logs = m_AppDbContext.p_LogsHalls.Include(l => l.p_User).Include(l => l.p_Seat).ThenInclude(s => s.p_Session).ThenInclude(s => s.p_Hall).Include(l => l.p_PromoCode) .Where(l => l.p_Date >= dateStart && l.p_Date <= dateEnd); return(await a_Grid.f_Execute(m_AppDbContext, logs)); } return(new EmptyResult()); }
public ActionResult TableSessionStatistic(Ctrl_Table.Cl_Params <Cl_Session> a_Grid) { if (a_Grid.p_Action == Ctrl_Table.E_Actions.Read && a_Grid != null) { IQueryable <Cl_Seat> source = m_AppDbContext.p_Seats; var jsonSerializerSettings = new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }; //if (source != null) { // var seats = m_AppDbContext.p_Seats.Where(s => s.p_TypeEmployment == Cl_Seat.E_TypeEmployment.Purchased).Include(s => s.p_Session).Include(s => s.p_Session.p_Hall); // if (a_Grid.p_Filter != null) { // var tInfoSource = source.ElementType.GetTypeInfo(); // string query = "select * from T_SEATS"; // int i = 0; // foreach (JProperty item in a_Grid.p_Filter) { // string filter = item.Value.ToString().ToLower(); // //MemberInfo memInfo = f_GetMember(source.ElementType, item.Name); // PropertyInfo propInfo = GetProperty(source.ElementType, item.Name); // if (propInfo == null) // return new EmptyResult(); // IEnumerable<ColumnAttribute> attrs = propInfo.GetCustomAttributes<ColumnAttribute>(); // ColumnAttribute attribute = attrs.FirstOrDefault(); // if (attribute != null) { // if (i == 0) { // query += " where "; // } else { // query += " or "; // } // query += string.Format("lower({0}) LIKE '%{1}%'", attribute.Name, filter); // i++; // } // //var memberInfo = tInfoSource.GetMember(item.Name); // //if (memberInfo == null) return new EmptyResult(); // //if (memberInfo.Length > 0) { // // IEnumerable<ColumnAttribute> attrs = memberInfo[0].GetCustomAttributes<ColumnAttribute>(); // // ColumnAttribute attribute = attrs.FirstOrDefault(); // // if (attribute != null) { // // if (i == 0) { // // query += " where "; // // } else { // // query += " or "; // // } // // query += string.Format("lower({0}) LIKE '%{1}%'", attribute.Name, filter); // // i++; // // } // //} // } // int count = source.FromSql(query).Count(); // if (!string.IsNullOrWhiteSpace(a_Grid.p_SortColumn) && !string.IsNullOrWhiteSpace(a_Grid.p_Direction)) { // query += string.Format(" order by {0} {1}", a_Grid.p_SortColumn, a_Grid.p_Direction); // } // var items = source.FromSql(query); // if (items != null) { // return new JsonResult(new { total = count, rows = items }, jsonSerializerSettings); // } else { // return new EmptyResult(); // } // } //} else { // return new EmptyResult(); //} string fHallName = ""; string fSessionName = ""; if (a_Grid.p_Filter != null) { foreach (JProperty item in a_Grid.p_Filter.Children()) { string filter = item.Value.ToString().ToLower(); if (item.Name == "p_Session.p_Hall.p_Name") { fHallName = filter; } if (item.Name == "p_Session.p_Name") { fSessionName = filter; } } } var seats = m_AppDbContext.p_Seats.Where(s => s.p_TypeEmployment == Cl_Seat.E_TypeEmployment.Purchased && s.p_Session.p_Hall.p_Name.Contains(fHallName) && s.p_Session.p_Name.Contains(fSessionName)) .Include(s => s.p_Session).ThenInclude(s => s.p_Hall).GroupBy(s => s.p_Session).Select(g => new { p_Session = g.Key, p_TotalCount = g.Count(), p_TotalSum = g.Sum(p => p.p_Price) }); if (!string.IsNullOrWhiteSpace(a_Grid.p_SortColumn) && !string.IsNullOrWhiteSpace(a_Grid.p_Direction)) { seats = seats.f_OrderBy(a_Grid.p_SortColumn, a_Grid.p_Direction); } return(new JsonResult(new { total = seats.Count(), rows = seats }, jsonSerializerSettings)); } return(new EmptyResult()); }