public IHttpActionResult GetRankOfOrganization(int orgId) { try { RankingDTO rankOfOrganization; using (var db = new OrganizationDAL()) { Organization org = db.GetOrganizationById(orgId); WsRanking ranking = new WsRanking(); rankOfOrganization = ranking.RankingWithPoint(org.Point); } return(Ok(new HTTPMessageDTO { Status = WsConstant.HttpMessageType.SUCCESS, Message = "", Type = "", Data = rankOfOrganization })); } catch (Exception) { return(Ok(new HTTPMessageDTO { Status = WsConstant.HttpMessageType.ERROR, Message = "", Type = "" })); } }
public OrganizationBasicInfo GetFullOrganizationBasicInformation(int orgId) { OrganizationBasicInfo organizationBasic = new OrganizationBasicInfo(); try { Organization org = GetOrganizationById(orgId); organizationBasic.OrganizationId = orgId; if (org != null) { organizationBasic.OrganizationName = org.OrganizationName; organizationBasic.Introduction = org.Introduction; organizationBasic.LogoUrl = org.LogoUrl; organizationBasic.Phone = org.Phone; organizationBasic.Email = org.Email; organizationBasic.Address = org.Address; organizationBasic.IsActive = org.IsActive; organizationBasic.IsVerify = org.IsVerify; organizationBasic.CreatedDate = org.CreatedDate.ToString("H:mm:ss dd/MM/yy"); organizationBasic.Point = org.Point; using (var db = new Ws_DataContext()) { organizationBasic.CreatorName = db.Organizations.Where(x => x.OrganizationId == orgId).SingleOrDefault().Ws_User.UserName; organizationBasic.NumberOfEvent = db.Events.Where(x => x.CreatorID == organizationBasic.OrganizationId).Count(); } WsRanking ranking = new WsRanking(); RankingDTO rank = ranking.RankingWithPoint(org.Point); if (rank.CurrentRank == 0) { organizationBasic.CurrentRank = "Mới"; } else if (rank.CurrentRank == 200) { organizationBasic.CurrentRank = "Đồng"; } else if (rank.CurrentRank == 500) { organizationBasic.CurrentRank = "Bạc"; } else if (rank.CurrentRank == 2000) { organizationBasic.CurrentRank = "Vàng"; } else if (rank.CurrentRank == 5000) { organizationBasic.CurrentRank = "Bạch Kim"; } else if (rank.CurrentRank == 10000) { organizationBasic.CurrentRank = "Kim Cương"; } //get creator using (var db = new UserDAL()) { organizationBasic.Creator = db.GetFullInforOfUserAsBasicUser(orgId); } } } catch (Exception) { //throw; } return(organizationBasic); }
/// <summary> /// Get full information of User /// #Note: If you add new field to UserBasicInfoDTO model - /// Please write code to set that information in this function /// </summary> /// <param name="userId"></param> /// <returns>UserBasicInfoDTO</returns> public UserBasicInfoDTO GetFullInforOfUserAsBasicUser(int userId) { UserBasicInfoDTO currentUser = new UserBasicInfoDTO(); int numberEventDonatedIn = 0; decimal totalMoneyDonatedIn = 0; decimal lastDonateMoney = 0; string lastDonateDate = ""; int numberOfPost = 0; try { Ws_User wsUser = GetUserById(userId); User_Information userInformation = GetUserInformation(userId); //Get infomation about donation of this user using (var db = new DonationDAL()) { numberEventDonatedIn = db.GetNumberEventDonatedInByUsingUserId(userId); totalMoneyDonatedIn = db.GetTotalMoneyDonatedInByUsingUserId(userId); Donation lastDonation = db.GetLastDonateInformation(userId); if (lastDonation != null) { lastDonateMoney = lastDonation.DonatedMoney; lastDonateDate = lastDonation.DonatedDate.ToString("H:mm:ss dd/MM/yy"); } } //Get number of post for current user using (var db = new ThreadDAL()) { numberOfPost = db.GetNumberOfPostPerUser(userId); } using (var db = new OrganizationDAL()) { Organization org = db.GetOrganizationById(userId); if (org != null) { currentUser.OrganazationName = org.OrganizationName; } if (currentUser.OrganazationName == "") { currentUser.OrganazationName = "Chưa có"; } } using (var db = new Ws_DataContext()) { currentUser.JoinedDate = db.Ws_User.Where(x => x.UserID == userId).SingleOrDefault().CreatedDate.ToString("dd/mm/yyyy"); } //get ranking information WsRanking ranking = new WsRanking(); RankingDTO rank = new RankingDTO(); //Set information for user which want to get currentUser.UserId = userId; currentUser.UserName = wsUser.UserName; currentUser.AccountType = wsUser.AccountType; currentUser.IsActive = wsUser.IsActive; currentUser.IsVerify = wsUser.IsVerify; currentUser.Email = wsUser.Email; if (userInformation != null) { rank = ranking.RankingWithPoint(userInformation.Point); currentUser.FacebookUri = userInformation.FacebookUrl; currentUser.FullName = userInformation.FullName; currentUser.ProfileImage = userInformation.ProfileImage; currentUser.Gender = userInformation.Gender; currentUser.Phone = userInformation.Phone; currentUser.Address = userInformation.UserAddress; currentUser.UserSignature = userInformation.UserSignature; if (userInformation.DoB != null) { currentUser.DOB = userInformation.DoB.Value.ToString("dd/MM/yyyy"); } currentUser.Country = userInformation.Country; currentUser.FacebookUri = userInformation.FacebookUrl; currentUser.CreateDate = wsUser.CreatedDate.ToString("dd/MM/yyyy"); currentUser.Point = userInformation.Point; } currentUser.NumberOfPost = numberOfPost; if (rank.CurrentRank == 0) { currentUser.CurrentRank = "Mới"; } else if (rank.CurrentRank == 200) { currentUser.CurrentRank = "Đồng"; } else if (rank.CurrentRank == 500) { currentUser.CurrentRank = "Bạc"; } else if (rank.CurrentRank == 2000) { currentUser.CurrentRank = "Vàng"; } else if (rank.CurrentRank == 5000) { currentUser.CurrentRank = "Bạch Kim"; } else if (rank.CurrentRank == 10000) { currentUser.CurrentRank = "Kim Cương"; } currentUser.RankPercent = rank.RankPercent; currentUser.NumberEventDonatedIn = numberEventDonatedIn; currentUser.TotalMoneyDonatedIn = totalMoneyDonatedIn; currentUser.LastDonateMoney = lastDonateMoney; currentUser.LastDonateDate = lastDonateDate; } catch (Exception) { //throw; } return(currentUser); }