public Object getUserByHouseId(int?houseId) { if (houseId == null) { return(null); } House curHouse = houseService.FindById(houseId.Value); if (curHouse == null) { return("error"); } User curUser = userService.findById(int.Parse(User.Identity.GetUserId())); if (curHouse.DisplayMember == false && curUser.HouseId != curHouse.Id) { return("NOT_PERMISSION"); } List <User> result = userService.findByHouseId(houseId.Value); // Serializer settings JsonSerializerSettings settings = new JsonSerializerSettings(); settings.ContractResolver = new CustomResolver(typeof(User)); settings.PreserveReferencesHandling = PreserveReferencesHandling.None; settings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore; settings.Formatting = Formatting.Indented; // Do the serialization and output to the console string json = JsonConvert.SerializeObject(result, settings); return(json); }
public ActionResult Index(int?houseId) { House curHouse = null; if (houseId == null) { return(RedirectToAction("Index", "Home")); } else { curHouse = houseService.FindById(houseId.Value); if (curHouse == null) { return(RedirectToAction("Index", "Home")); } } User curUser = userService.findById(int.Parse(User.Identity.GetUserId())); if (curUser == null) { return(View("Error")); } if (curHouse.AllowOtherView == false && curUser.HouseId != curHouse.Id) { return(View("NotDisplay")); } List <User> members = userService.findByHouseId(curHouse.Id); ViewBag.curUser = curUser; ViewBag.curHouse = curHouse; ViewBag.members = members; return(View()); }
public ActionResult DoSurvey() { User currentUser = userService.FindById(int.Parse(User.Identity.GetUserId())); House currentHouse = null; if (currentUser.HouseId == null && currentUser.HouseId.HasValue) { currentHouse = houseServices.FindById(currentUser.HouseId.Value); } List <UserAnswerPoll> listUserAnswer = new List <UserAnswerPoll>(); List <Poll> lists = new List <Poll>(); List <Poll> listSurveys = PollService.GetListPolls(); List <UserAnswerPoll> listUserAnswerPolls = userAnswerService.GetListUserAnswerPollsByPollId(); List <UserAnswerPoll> listAnswerSurveys = userAnswerService.GetListUserAnswerPoll(); List <UserAnswerPoll> list = new List <UserAnswerPoll>(); List <int> listPollId = new List <int>(); foreach (var o in listUserAnswerPolls) { listPollId.Add(o.PollId); } foreach (var obj in listPollId) { list = userAnswerService.GetListUserAnswerPollsByPollId(obj); } foreach (var item in listSurveys) { if (DateTime.Now >= item.PublishDate && DateTime.Now <= item.EndDate) { listUserAnswer = (userAnswerService.GetListUserAnswerPollsByPollId(item.Id)); List <BlockPoll> listBlockPolls = BlockPollService.FindByPollId(item.Id); int k = 0; int p = 0; if (listSurveys.Count != 0) { if (item.Mode == 1 && item.Status == 1) { foreach (var VARIABLE in listUserAnswer) { if (VARIABLE.UserId == currentUser.Id) { k++; } } foreach (var obj in listBlockPolls) { if (currentUser.HouseId != null) { if (obj.BlockId == BlockPollService.FindBlockIdByHouseId(currentUser.HouseId.Value).BlockId) { p++; } } } if ((k != 1 && p == 1 && item.Status == 1)) //if (k != 1) { //po.Question = item.Question; //po.Answer1 = item.Answer1; //po.Answer2 = item.Answer2; //po.Answer3 = item.Answer3; //po.Answer4 = item.Answer4; //po.Answer5 = item.Answer5; //po.EndDate = item.EndDate; lists.Add(item); } else if (k != 1 && listBlockPolls.Count == 0 && item.Status == 1) { lists.Add(item); } } else if (item.Mode == 2 && currentUser.RoleId == 4 && item.Status == 1) { foreach (var VARIABLE in listUserAnswer) { if (VARIABLE.UserId == currentUser.Id) { k++; } } foreach (var obj in listBlockPolls) { if (obj.BlockId == BlockPollService.FindBlockIdByHouseId(currentUser.HouseId.Value).BlockId) { p++; } } if (k != 1 && p == 1 && item.Status == 1) // if (k != 1) { lists.Add(item); } else if (k != 1 && listBlockPolls.Count == 0 && item.Status == 1) { lists.Add(item); } } else if ((item.Mode == 3 && currentUser.RoleId == 4 && item.Status == 1) || (item.Mode == 3 && currentUser.RoleId == 3 && item.Status == 1)) { foreach (var VARIABLE in listUserAnswer) { if (VARIABLE.UserId == currentUser.Id) { k++; } } foreach (var obj in listBlockPolls) { if (obj.BlockId == BlockPollService.FindBlockIdByHouseId(currentUser.HouseId.Value).BlockId) { p++; } } if (k != 1 && p == 1 && item.Status == 1) // if (k != 1) { lists.Add(item); } else if (k != 1 && listBlockPolls.Count == 0 && item.Status == 1) { lists.Add(item); } } } else if (listSurveys.Count == 0) { } } } ViewBag.ListSurveys = lists; // int a = listCount.Count; ViewBag.ListUserAnswerPoll = listAnswerSurveys; ViewBag.List = list; ViewBag.ListSurvey = listSurveys; ViewBag.ListUserAnswer = listPollId; ViewBag.currentUser = currentUser; // ViewBag.currentHouse = currentHouse; return(View()); }
public ActionResult AddNewResident(UserInfoViewModel user) { MessageViewModels response = new MessageViewModels(); if (null != user.HouseId) { try { House house = _houseServices.FindById(user.HouseId); if (null != house) { User u = new User(); if (house.Status == SLIM_CONFIG.HOUSE_STATUS_ENABLE && house.OwnerID == null && user.IsHouseOwner == SLIM_CONFIG.USER_ROLE_RESIDENT) { response.StatusCode = 2; response.Msg = "Nhà này vẫn chưa có chủ hộ !"; return(Json(response)); } u.Fullname = user.Name; u.HouseId = house.Id; u.CreateDate = DateTime.Now; u.LastModified = DateTime.Now; u.IDNumber = user.Idenity; u.Status = SLIM_CONFIG.USER_STATUS_ENABLE; u.Gender = user.Gender; u.DateOfBirth = DateTime.ParseExact(user.Dob, AmsConstants.DateFormat, CultureInfo.CurrentCulture); if (user.IdCreateDate != null) { u.IDCreatedDate = DateTime.ParseExact(user.IdCreateDate, AmsConstants.DateFormat, CultureInfo.CurrentCulture); } u.Username = user.UserAccountName; u.Creator = Int32.Parse(User.Identity.GetUserId()); u.RoleId = user.IsHouseOwner; u.FamilyLevel = user.RelationLevel; if (user.IsHouseOwner == SLIM_CONFIG.USER_ROLE_HOUSEHOLDER) { u.FamilyLevel = 0; // At the center row in house } u.Password = CommonUtil.GetUniqueKey(8); u.SendPasswordTo = user.CellNumb; _userServices.Add(u); if (user.IsHouseOwner == SLIM_CONFIG.USER_ROLE_HOUSEHOLDER) { house.OwnerID = u.Id; _houseServices.Update(house); foreach (var userInHouse in house.Users.Where(usr => usr.Id != u.Id && u.RoleId == SLIM_CONFIG.USER_ROLE_HOUSEHOLDER) ) { User usr = _userServices.FindById(userInHouse.Id); usr.RoleId = SLIM_CONFIG.USER_ROLE_RESIDENT; usr.LastModified = DateTime.Now; _userServices.Update(usr); } } StringBuilder message = new StringBuilder(); message.Append("Chung cu AMS. Tai khoan duoc tao thanh cong! Ten đang nhap: ") .Append(u.Username) .Append(". Mat khau: ") .Append(u.Password); CommonUtil.SentSms(u.SendPasswordTo, message.ToString()); // var accountSid = "AC10ae7ed64035004a9f1ed772747b94dc"; // Your Account SID from www.twilio.com/console // var authToken = "c867c6dadb271752b1fa0bb988f1c284"; // Your Auth Token from www.twilio.com/console // // var twilio = new TwilioRestClient(accountSid, authToken); // var message = twilio.SendMessage( // "+12057198424", // From (Replace with your Twilio number) // "+84934876200", // To (Replace with your phone number) // "One time password: chào bạn" // ); // // Console.WriteLine(message.Sid); // Console.Write("Press any key to continue."); // Console.ReadKey(); } else { response.StatusCode = -1; } } catch (Exception) { response.StatusCode = -1; return(Json(response)); } } else { response.StatusCode = -1; } return(Json(response)); }