Exemplo n.º 1
0
        public String ChangeProfile(int houseId, String dir)
        {
            House h = houseService.FindById(houseId);

            if (h == null)
            {
                return("error");
            }
            else
            {
                h.ProfileImage = dir;
            }
            houseService.Update(h);
            return("success");
        }
Exemplo n.º 2
0
        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));
        }