public List <EventBasicInfo> GetTopEventSortByMoneyDonateIn(int top) { List <EventBasicInfo> eventList = new List <EventBasicInfo>(); try { List <int> eventIdList; using (var db = new Ws_DataContext()) { eventIdList = db.Donations.Select(x => x.EventId).Distinct().ToList(); } List <EventBasicInfo> eventFullList = new List <EventBasicInfo>(); foreach (int eventId in eventIdList) { EventBasicInfo e = GetFullEventBasicInformation(eventId); eventFullList.Add(e); } eventList = eventFullList.OrderByDescending(x => x.RaisedMoney).Take(top).ToList(); } catch (Exception) { //throw; } return(eventList); }
public List <EventBasicInfo> GetAllEvents() { var listEvent = new List <EventBasicInfo>(); try { List <int> IdList; using (var db = new Ws_DataContext()) { IdList = db.Events.Select(x => x.EventID).ToList(); } using (var db = new EventDAL()) { foreach (int eventId in IdList) { EventBasicInfo eventBasic = db.GetFullEventBasicInformation(eventId); listEvent.Add(eventBasic); } } } catch (Exception) { //throw; } return(listEvent); }
public EventBasicInfo GetEventBasicInfoById(int eventId) { EventBasicInfo EvtBasicInfo = new EventBasicInfo(); using (var db = new Ws_DataContext()) { var currentEvent = db.Events.FirstOrDefault(x => x.EventID == eventId); EvtBasicInfo.CreatorID = currentEvent.CreatorID; EvtBasicInfo.CreatorName = currentEvent.Organization.OrganizationName; EvtBasicInfo.VideoUrl = currentEvent.VideoUrl; EvtBasicInfo.EventName = currentEvent.EventName; EvtBasicInfo.EventType = currentEvent.EType.EventTypeName; EvtBasicInfo.CreatedDate = currentEvent.Created_Date.ToString("dd/MM/yyyy"); EvtBasicInfo.Content = currentEvent.Description; EvtBasicInfo.ExpectedMoney = currentEvent.ExpectedMoney; EvtBasicInfo.Location = currentEvent.Location; EvtBasicInfo.ContactInfo = currentEvent.Contact; EvtBasicInfo.ShortDescription = currentEvent.ShortDescription; EvtBasicInfo.Start_Date = currentEvent.Start_Date.ToString("dd/MM/yyyy");; EvtBasicInfo.Finish_Date = currentEvent.Finish_Date.ToString("dd/MM/yyyy"); EvtBasicInfo.CreatorUserName = currentEvent.Organization.Ws_User.UserName; } //Get ImageAlbum using (var db = new Ws_DataContext()) { var imgInEvent = (from p in db.EventAlbum where p.EventId == eventId select p.ImageUrl).ToList(); EvtBasicInfo.ImageAlbum = imgInEvent; } return(EvtBasicInfo); }
public IHttpActionResult GetEventDetailById(int id) { EventBasicInfo EvtBasicInfo = new EventBasicInfo(); try { using (var db = new EventDAL()){ EvtBasicInfo = db.GetFullEventBasicInformation(id); } }catch (Exception) { return(Redirect("/#/Error")); } return(Ok(new HTTPMessageDTO { Status = WsConstant.HttpMessageType.SUCCESS, Data = EvtBasicInfo })); }
public List <EventBasicInfo> GetTopNewEvent() { var topEvent = new List <EventBasicInfo>(); try { List <int> listEventId; using (var db = new Ws_DataContext()) { listEventId = db.Events.OrderByDescending(x => x.Created_Date).Select(x => x.EventID).Take(10).ToList(); } foreach (int userId in listEventId) { EventBasicInfo eventBasic = GetFullEventBasicInformation(userId); topEvent.Add(eventBasic); } } catch (Exception) { //throw; } return(topEvent); }
public EventBasicInfo GetFullEventBasicInformation(int eventId) { EventBasicInfo eventBasicInfo = new EventBasicInfo(); try { Event wsEvent; string creatorUserName = ""; string creatorName = ""; string organizationName = ""; List <string> imageAlbum; decimal raisedMoney; using (var db = new Ws_DataContext()) { //Get event model wsEvent = db.Events.FirstOrDefault(x => x.EventID == eventId); //Get user name var userGet1 = db.Ws_User.FirstOrDefault(x => x.UserID == wsEvent.CreatorID); if (userGet1 != null) { creatorUserName = userGet1.UserName; } //Get user full name var userGet2 = db.User_Information.FirstOrDefault(x => x.UserID == wsEvent.CreatorID); if (userGet2 != null) { creatorName = userGet2.FullName; } //Get image album imageAlbum = db.EventAlbum.Where(x => x.EventId == eventId).Select(x => x.ImageUrl).ToList(); var organiGet = db.Organizations.FirstOrDefault(x => x.OrganizationId == wsEvent.CreatorID); if (organiGet != null) { organizationName = organiGet.OrganizationName; } //Get total money which has been raised raisedMoney = GetTotalRaisedMoneyOfEvent(eventId); // Get main image string mainImageUrl = GetMainImageEventById(eventId).ImageUrl; //Get image album eventBasicInfo.EventID = eventId; eventBasicInfo.CreatorID = wsEvent.CreatorID; eventBasicInfo.CreatorUserName = creatorUserName; eventBasicInfo.OrganizationName = organizationName; eventBasicInfo.CreatorName = creatorName; eventBasicInfo.OrganizationName = wsEvent.Organization.OrganizationName; eventBasicInfo.CreatorName = creatorName; eventBasicInfo.EventName = wsEvent.EventName; eventBasicInfo.ShortDescription = wsEvent.ShortDescription; eventBasicInfo.Content = wsEvent.Description; eventBasicInfo.ContactInfo = wsEvent.Contact; eventBasicInfo.MainImageUrl = mainImageUrl; eventBasicInfo.ImageAlbum = imageAlbum; eventBasicInfo.Location = wsEvent.Location; eventBasicInfo.VideoUrl = wsEvent.VideoUrl; eventBasicInfo.Status = wsEvent.Status; eventBasicInfo.IsOpen = wsEvent.IsOpen; if (!wsEvent.Status) { eventBasicInfo.TimeStatus = "ban"; } else if (wsEvent.Status && DateTime.Now > wsEvent.Finish_Date) { eventBasicInfo.TimeStatus = "done"; } else if (wsEvent.Status && DateTime.Now < wsEvent.Start_Date) { eventBasicInfo.TimeStatus = "income"; } else { eventBasicInfo.TimeStatus = "process"; } eventBasicInfo.DonatedUser = CountDonatedUserOfEvent(eventId); eventBasicInfo.Likes = CountLikeInEvent(eventId); eventBasicInfo.NumberOfComments = CountCommentInEvent(eventId); eventBasicInfo.ExpectedMoney = wsEvent.ExpectedMoney; eventBasicInfo.RaisedMoney = raisedMoney; eventBasicInfo.DonatePercent = raisedMoney / (decimal)wsEvent.ExpectedMoney * 100; eventBasicInfo.EventType = wsEvent.EType.EventTypeName; eventBasicInfo.CreatedDate = wsEvent.Created_Date.ToString("dd/MM/yyyy"); eventBasicInfo.Start_Date = wsEvent.Start_Date.ToString("dd/MM/yyyy"); eventBasicInfo.Finish_Date = wsEvent.Finish_Date.ToString("dd/MM/yyyy"); } } catch (Exception) { //throw; } return(eventBasicInfo); }