Exemple #1
0
        /// <summary>
        /// 创建用户
        /// </summary>
        /// <returns></returns>
        public static User CreateUser(string MibleNumber)
        {
            //防止数据库同步时差 导致重复创建账号 Sleep 2s
            System.Threading.Thread.Sleep(2000);
            using (var client = new UserAccountClient())
            {
                var password = new Random().Next(100000, 1000000).ToString();
                CreateUserRequest request = new CreateUserRequest
                {
                    MobileNumber   = MibleNumber,
                    ChannelIn      = nameof(ChannelIn.H5),
                    Password       = password,
                    Profile        = new UserProfile(),
                    UserCategoryIn = nameof(UserCategoryIn.Tuhu)
                };
                var Result = client.CreateUserRequest(request);

                Result.ThrowIfException(true);
                if (Result.Success && Result.Result != null)
                {
                    Log(UserActionEnum.Register, Result.Result.UserId, "chexian_创建用户,CreateUser:成功");
                    return(Result.Result);
                }
                else
                {
                    Log(UserActionEnum.Register, null, "chexian_创建用户,CreateUser:失败");
                    return(null);
                }
            }
        }
Exemple #2
0
 /// <summary>
 /// 获取用户信息by phone
 /// </summary>
 /// <param name="Phone"></param>
 /// <returns></returns>
 public static User GetUserByPhone(string Phone)
 {
     try
     {
         using (var client = new UserAccountClient())
         {
             var clientResult = client.GetUserByMobile(Phone);
             if (clientResult.Success && clientResult.Result != null)
             {
                 Log(UserActionEnum.Login, clientResult.Result.UserId, "chexian_获取用户信息,GetUserByPhone:成功");
                 return(clientResult.Result);
             }
             else
             {
                 Log(UserActionEnum.Login, null, "chexian_获取用户信息,GetUserByMobileAsync:失败");
                 return(null);
             }
         }
     }
     catch (Exception ex)
     {
         WebLog.LogException(ex);
         return(null);
     }
 }
        public ViewResult ChangeMobileBindingOnDate(string SearchStartDate, string SearchEndDate)
        {
            IEnumerable <UserChangeBindMobileLog> changeMobileBindingLogs = new List <UserChangeBindMobileLog>();

            if (!string.IsNullOrEmpty(SearchStartDate) && !string.IsNullOrEmpty(SearchEndDate))
            {
                DateTime startTime, endTime;
                if (DateTime.TryParse(SearchStartDate, out startTime) && DateTime.TryParse(SearchEndDate, out endTime))
                {
                    try
                    {
                        using (var client = new UserAccountClient())
                        {
                            var result = client.QueryChangeBindMobileLogByDateTime(startTime, endTime);
                            result.ThrowIfException(true);
                            if (result.Success && result.Result != null)
                            {
                                changeMobileBindingLogs = result.Result;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        WebLog.LogException(ex);
                    }
                }
            }
            ViewBag.SearchStartDate = SearchStartDate;
            ViewBag.SearchEndDate   = SearchEndDate;
            return(View("ChangeMobileBinding", changeMobileBindingLogs));
        }
        public ViewResult ChangeMobileBindingOnMobile(string mobileToFind)
        {
            IEnumerable <UserChangeBindMobileLog> changeMobileBindingLogs = new List <UserChangeBindMobileLog>();

            if (!string.IsNullOrEmpty(mobileToFind))
            {
                try
                {
                    using (var client = new UserAccountClient())
                    {
                        var result = client.QueryChangeBindMobileLogByMobile(mobileToFind);
                        result.ThrowIfException(true);
                        if (result.Success && result.Result != null)
                        {
                            changeMobileBindingLogs = result.Result;
                        }
                    }
                }
                catch (Exception ex)
                {
                    WebLog.LogException(ex);
                }
            }
            ViewBag.mobileToFind = mobileToFind;
            return(View("ChangeMobileBinding", changeMobileBindingLogs));
        }
        public async Task <JsonResult> SubmitChangeBindingAction(string oldNumber, string newNumber, string vCode)
        {
            try
            {
                using (var client = new UserAccountClient())
                {
                    var result = await client.ChangeBindMobileActionAsync(new UserChangeBindMobileAction
                    {
                        Operator         = User.Identity.Name,
                        SourceBindMobile = oldNumber,
                        TargetBindMobile = newNumber,
                        TargetMobileCode = vCode
                    });

                    result.ThrowIfException(false);
                    if (result.Success && result.Result)
                    {
                        var flag    = false;
                        var smsBody = "您的途虎账号已经与本手机号解绑, 如非本人操作请联系客服:400-111-8868【途虎养车】";
                        // 提交验证码
                        await Business.Sms.SmsManager.SubmitVerficationCodeAsync(newNumber, vCode);

                        // 模板:您的途虎账号已经与本手机号解绑, 如非本人操作请联系客服:400-111-8868
                        if (await Business.Sms.SmsManager.SendTemplateSmsMessageAsync(oldNumber, 75))
                        {
                            flag = true;
                        }

                        await client.LogChangeBindMobileActionAsync(
                            new UserChangeBindMobileLog
                        {
                            SourceBindMobile = oldNumber,
                            TargetBindMobile = newNumber,
                            Operator         = User.Identity.Name,
                            OperateStatus    = true,
                            CreatedTime      = DateTime.Now
                        });

                        return(flag ? Json("绑定成功但发送确认短信失败") : Json("绑定成功"));
                    }
                    await client.LogChangeBindMobileActionAsync(
                        new UserChangeBindMobileLog
                    {
                        SourceBindMobile = oldNumber,
                        TargetBindMobile = newNumber,
                        Operator         = User.Identity.Name,
                        OperateStatus    = false,
                        FailReason       = result.ErrorMessage,
                        CreatedTime      = DateTime.Now
                    });

                    return(Json(result.ErrorMessage));
                }
            }
            catch (Exception exception)
            {
                WebLog.LogException(exception);
                return(Json("未知异常"));
            }
        }
Exemple #6
0
        public PartialViewResult LogOutUserByMobileInfo(string mobileNumber)
        {
            User info = new Service.UserAccount.Models.User();

            if (!string.IsNullOrWhiteSpace(mobileNumber))
            {
                try
                {
                    using (var client = new UserAccountClient())
                    {
                        var result = client.GetUserByMobile(mobileNumber);
                        result.ThrowIfException(true);
                        if (result.Success && result.Result != null)
                        {
                            info = result.Result;
                        }
                    }
                }
                catch (Exception ex)
                {
                    WebLog.LogException(ex);
                }
            }
            return(PartialView(info));
        }
        public ActionResult ChangePassword(string oldPassword, string newPassword, string confirmNewPassword)
        {
            if (AuthTokens == null)
            {
                return(RedirectToAction("LogIn"));
            }
            if (AuthTokens[0] == "demo")
            {
                ViewBag.Response = "You cannot change password in demo";
                return(View());
            }
            string            email   = AuthTokens[1];
            UserAccountClient uac     = new UserAccountClient();
            UserAccount       account = uac.GetByPartitionAndRowKey(UserAccountClient.GetPartitionKeyForEmail(email), email);

            if (account == null)
            {
                return(RedirectToAction("LogIn"));
            }
            else if (account.Password == oldPassword && Password.checkPassword(newPassword) && newPassword == confirmNewPassword)
            {
                account.Password = newPassword;
                uac.Update(account);
                SendPasswordChangeEmail(email);
                ViewBag.PasswordUpdated = true;
            }
            else if (account.Password != oldPassword)
            {
                ViewBag.InvalidPassword = true;
            }
            return(View());
        }
        /// <summary>
        /// 获取所有合作用户配置
        /// </summary>
        /// <returns></returns>
        public ActionResult GetAllMrCooperateUserConfigs()
        {
            var result = manager.GetAllMrCooperateUserConfigs();

            if (result != null)
            {
                var userIds     = result.Select(t => t.VipUserId).Distinct();
                var usersDetail = new List <SYS_CompanyUser>();
                using (var client = new UserAccountClient())
                {
                    foreach (var item in userIds)
                    {
                        var userResult = client.SelectCompanyUserInfo(item);
                        if (userResult.Success && userResult.Result != null)
                        {
                            usersDetail.Add(userResult.Result);
                        }
                    }
                }
                foreach (var item in result)
                {
                    var userDetail = usersDetail.FirstOrDefault(t => t.UserId == item.VipUserId);
                    if (userDetail != null)
                    {
                        item.VipUserName    = userDetail.UserName;
                        item.VipCompanyName = userDetail.CompanyInfo?.Name;
                        item.VipCompanyId   = userDetail.CompanyInfo?.Id ?? 0;
                    }
                }
            }

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
        public ActionResult SubmitSchool(FormCollection collection)
        {
            if (AuthTokens[0] == "demo")
            {
                ViewBag.DemoNextStep = NextStep("!");
                return(View());
            }
            string              admin        = AuthTokens[1];
            AdminAccountClient  aac          = new AdminAccountClient();
            AdminAccount        adminAccount = aac.GetByPartitionAndRowKey("admin", admin);
            UserAccountClient   uac          = new UserAccountClient();
            UserAccount         user         = uac.GetByPartitionAndRowKey(UserAccountClient.GetPartitionKeyForEmail(admin), admin);
            string              rowkey       = Regex.Replace(collection["schoolphone"], @"[^0-9]", "");
            string              phone        = rowkey.Substring(0, 3) + "-" + rowkey.Substring(3, 3) + "-" + rowkey.Substring(6);
            PendingSchoolClient psc          = new PendingSchoolClient();

            psc.AddNewItem(new PendingSchool {
                Admin = admin, SchoolName = collection["schoolname"], Address = collection["schooladdress1"], City = collection["schoolcity"], State = collection["schoolstate"], ZipCode = collection["schoolzip"], OfficialID = collection["schoolid"], PhoneNumber = phone, RowKey = rowkey
            });
            adminAccount.SchoolSelected = true;
            adminAccount.School         = rowkey;
            adminAccount.RequestStatus  = "";
            aac.Update(adminAccount);

            EmailManager emailManager = new EmailManager();
            string       body         = "<div>Admin name: " + user.FirstName + " " + user.LastName + "</div><div>Admin phone number and extension:" + adminAccount.PhoneNumber + " x " + adminAccount.PhoneExtension + "</div><div>Admin Email: " + adminAccount.RowKey + "</div>" +
                                        "<div>School name: " + collection["schoolname"] + "</div><div>School address" + collection["schooladdress1"] + " " + collection["schoolcity"] + " " + collection["schoolstate"] + " " + collection["schoolzip"] + "</div>" +
                                        "<div>School phone number: " + phone + "</div>";

            emailManager.SendMail("*****@*****.**", "Admin", "*****@*****.**", "School request", body);

            return(RedirectToAction("SchoolSubmitted"));
        }
Exemple #10
0
        public ActionResult Administrator(FormCollection collection)
        {
            UserAccountClient uac     = new UserAccountClient();
            UserAccount       account = uac.GetByPartitionAndRowKey(UserAccountClient.GetPartitionKeyForEmail(collection["email"].ToLower()), collection["email"].ToLower());

            if (account == null)
            {
                uac.AddNewItem(new UserAccount {
                    PartitionKey = UserAccountClient.GetPartitionKeyForEmail(collection["email"].ToLower()), RowKey = collection["email"].ToLower(), FirstName = collection["firstname"], LastName = collection["lastname"], Email = collection["email"], Password = collection["password"], ProfileType = "administrator"
                });

                //AdminProfileClient apc = new AdminProfileClient();
                //apc.AddNewItem(new AdminProfile { RowKey = collection["email"].ToLower(), PhoneNumber = collection["phonenumber"] });

                AdminAccountClient aac = new AdminAccountClient();
                aac.AddNewItem(new AdminAccount {
                    RowKey = collection["email"].ToLower(), PhoneNumber = collection["phonenumber"], PhoneExtension = collection["extension"]
                });
            }
            else
            {
                ViewBag.ErrorMessage = "There is an account already associated with this email. Please log in instead.";
                return(View());
            }

            SendVerificationEmail(collection["email"].ToLower(), collection["firstname"]);

            EmailManager emailManager = new EmailManager();
            string       str          = "<p>Full name: " + collection["firstname"] + " " + collection["lastname"] + "</p><p>Email: " + collection["email"] + "</p><p>Phone Number: " + collection["phonenumber"] + "</p><p>" + collection["extension"] + "</p>";

            emailManager.SendMail("*****@*****.**", "Admin", "*****@*****.**", "HS Admin", str);
            return(RedirectToAction("ThankYou"));
        }
        public ActionResult GetAllRecords()
        {
            UserAccountClient  uac   = new UserAccountClient();
            List <UserAccount> users = new List <UserAccount>(uac.GetAll());

            return(View());
        }
        public HttpResponse ResendEmail(string invite)
        {
            string response;

            if (AuthTokens[0] != "demo")
            {
                CounselorInviteClient cic         = new CounselorInviteClient();
                CounselorInvite       inviteEntry = cic.GetByPartitionAndRowKey("invite", invite);
                if (inviteEntry != null)
                {
                    UserAccountClient uac  = new UserAccountClient();
                    UserAccount       user = uac.GetByPartitionAndRowKey(UserAccountClient.GetPartitionKeyForEmail(AuthTokens[1].ToLower()), AuthTokens[1].ToLower());
                    SendInviteEmail(inviteEntry.Email, inviteEntry.FirstName + " " + inviteEntry.LastName, user.FirstName + " " + user.LastName, inviteEntry.RowKey);
                    response = "{\"result\": \"done\"}";
                }
                else
                {
                    response = "{\"result\": \"error\"}";
                }
            }
            else
            {
                response = "{\"result\": \"done\"}";
            }
            Response.ContentType = "application/json";
            Response.Write(response);
            Response.End();
            return(null);
        }
 public ActionResult Index(IEnumerable <string> firstname, IEnumerable <string> lastname, IEnumerable <string> email)
 {
     if (AuthTokens[0] == "demo")
     {
         ViewBag.DemoNextStep = NextStep("!");
         return(View());
     }
     if (firstname != null && lastname != null && email != null)
     {
         if (firstname.Count() == lastname.Count() && firstname.Count() == email.Count())
         {
             CounselorInviteClient cic   = new CounselorInviteClient();
             AdminAccountClient    aac   = new AdminAccountClient();
             UserAccountClient     uac   = new UserAccountClient();
             AdminAccount          admin = aac.GetByPartitionAndRowKey("admin", AuthTokens[1].ToLower());
             UserAccount           user  = uac.GetByPartitionAndRowKey(UserAccountClient.GetPartitionKeyForEmail(AuthTokens[1].ToLower()), AuthTokens[1].ToLower());
             string school = admin.School;
             for (var i = 0; i < firstname.Count(); i++)
             {
                 string emailLower = email.ElementAt(i).ToLower();
                 string guid       = ShortGuidGenerator.NewGuid();
                 cic.AddNewItem(new CounselorInvite {
                     FirstName = firstname.ElementAt(i), LastName = lastname.ElementAt(i), Email = emailLower, School = school, RowKey = guid
                 });
                 SendInviteEmail(email.ElementAt(i).ToLower(), firstname.ElementAt(i) + " " + lastname.ElementAt(i), user.FirstName + " " + user.LastName, guid);
             }
             return(View());
         }
     }
     ViewBag.ErrorMessage = "error";
     return(View());
 }
Exemple #14
0
        /// <summary>
        /// 查询或者创建用户
        /// </summary>
        /// <param name="mobile"></param>
        /// <param name="userName"></param>
        /// <param name="nickName"></param>
        /// <param name="headUrl"></param>
        /// <returns></returns>
        public static User GetOrCreateUser(string mobile, string userName = null, string nickName = null, string headUrl = null)
        {
            User user = null;

            if (!string.IsNullOrEmpty(mobile))
            {
                using (var client = new UserAccountClient())
                {
                    var result = client.GetUserByMobile(mobile);
                    result.ThrowIfException(true);
                    user = result.Result;
                    if (user == null)
                    {
                        var createResult = client.CreateUserRequest(
                            new CreateUserRequest
                        {
                            MobileNumber = mobile,
                            Profile      = new UserProfile
                            {
                                UserName = userName,
                                NickName = nickName,
                                HeadUrl  = headUrl
                            },
                            ChannelIn      = nameof(ChannelIn.None),
                            UserCategoryIn = nameof(UserCategory.Tuhu),
                        });
                        createResult.ThrowIfException(true);
                        user = createResult.Result;
                    }
                }
            }

            return(user);
        }
        public ActionResult Report(string id)
        {
            if (id != null && id != "")
            {
                StudentAccountClient sac     = new StudentAccountClient();
                StudentAccount       student = sac.GetByPartitionAndRowKey(StudentAccountClient.GetPartitionKeyForEmail(id), id);

                //StudentProfileClient spc = new StudentProfileClient();
                //StudentProfile student = spc.GetByPartitionAndRowKey(StudentProfileClient.GetPartitionKeyForEmail(id), id);
                if (student != null && AuthTokens[3] == "administrator" && student.Counselor == AuthTokens[1])
                {
                    UserAccountClient uac     = new UserAccountClient();
                    UserAccount       account = uac.GetByPartitionAndRowKey(UserAccountClient.GetPartitionKeyForEmail(id), id);
                    // ViewBag.StudentName = account.FirstName + " " + account.LastName;
                    ViewBag.StudentFirstName = account.FirstName;
                    ViewBag.StudentLastName  = account.LastName;
                    ViewBag.StudentToShow    = id;
                }
            }
            else if (AuthTokens[3] == "administrator")
            {
                return(RedirectToAction("Assessment", "Index"));
            }
            return(View());
        }
Exemple #16
0
        private void LogOutUserByUserId(string userId)
        {
            if (!string.IsNullOrWhiteSpace(userId))
            {
                Guid uId = new Guid(userId);
                try
                {
                    using (var client = new AccessTokenClient())
                    {
                        var result = client.RemoveAll(uId, "Setting站点工具登出");
                        result.ThrowIfException(true);
                    }

                    using (var useraccoutClient = new UserAccountClient())
                    {
                        var insertLog = useraccoutClient.LogUserAction(new UserLog
                        {
                            Action      = UserActionEnum.LogOut,
                            CreatedTime = DateTime.Now,
                            UserId      = uId,
                            ChannelIn   = nameof(ChannelIn.H5),
                            Content     = "Setting站点内手动登出该用户"
                        });
                        insertLog.ThrowIfException(true);
                    }
                }
                catch (Exception ex)
                {
                    WebLog.LogException(ex);
                }
            }
        }
Exemple #17
0
        public JsonResult LogOffUserById(string userId, string mobile)
        {
            int flag = 0;

            if (!string.IsNullOrWhiteSpace(userId) && !string.IsNullOrWhiteSpace(mobile))
            {
                Guid uId = new Guid(userId);
                try
                {
                    var existYlh     = false;
                    var logoffResult = false;
                    using (var ylhClient = new YLHUserAccountClient())
                    {
                        var ylhUser = ylhClient.GetYLHUserInfoByMobile(mobile);
                        ylhUser.ThrowIfException(true);
                        if (ylhUser.Result != null && ylhUser.Result.UserId != Guid.Empty)
                        {
                            existYlh = true;
                        }
                    }

                    if (existYlh)
                    {
                        flag = -1;
                    }
                    else
                    {
                        using (var client = new UserAccountClient())
                        {
                            var logoff = client.LogOffUser(uId);
                            logoff.ThrowIfException(true);
                            logoffResult = logoff.Result;
                        }
                        if (logoffResult)
                        {
                            flag = 1;
                        }

                        using (var useraccoutClient = new UserAccountClient())
                        {
                            var insertLog = useraccoutClient.LogUserAction(new UserLog
                            {
                                Action      = UserActionEnum.LogOff,
                                CreatedTime = DateTime.Now,
                                UserId      = uId,
                                ChannelIn   = nameof(ChannelIn.H5),
                                Content     = ThreadIdentity.Operator.Name + "在Setting站点内手动注销该用户"
                            });
                            insertLog.ThrowIfException(true);
                        }
                    }
                }
                catch (Exception ex)
                {
                    WebLog.LogException(ex);
                }
            }
            return(Json(flag));
        }
        public ActionResult ConfirmEmail(string id)
        {
            if (id != null)
            {
                SimpleAES         aes     = new SimpleAES();
                string            email   = aes.DecryptString(id);
                UserAccountClient uac     = new UserAccountClient();
                UserAccount       account = uac.GetByPartitionAndRowKey(UserAccountClient.GetPartitionKeyForEmail(email), email);
                if (account != null)
                {
                    account.EmailConfirmed = true;
                    uac.Update(account);
                    if (account.ProfileType == "student")
                    {
                        StudentAccountClient sac     = new StudentAccountClient();
                        StudentAccount       student = sac.GetByPartitionAndRowKey(StudentAccountClient.GetPartitionKeyForEmail(account.Email), account.Email);

                        //StudentProfileClient spc = new StudentProfileClient();
                        //StudentProfile student = spc.GetByPartitionAndRowKey(UserAccountClient.GetPartitionKeyForEmail(account.Email), account.Email);
                        string sessionkey = ClientSession.GetClientSessionKey("user", account.Email, account.FirstName + " " + account.LastName, "student");
                        Response.Cookies["sessionkey"].Value        = sessionkey;
                        Response.Cookies["sessionkey"].Expires      = DateTime.UtcNow.AddDays(7);
                        Response.Cookies["sessionusername"].Value   = account.Email;
                        Response.Cookies["sessionusername"].Expires = DateTime.UtcNow.AddDays(7);
                        Response.Cookies["firstname"].Value         = account.FirstName;
                        Response.Cookies["firstname"].Expires       = DateTime.UtcNow.AddDays(7);
                        Response.Cookies["lastname"].Value          = account.LastName;
                        Response.Cookies["lastname"].Expires        = DateTime.UtcNow.AddDays(7);
                        Response.Cookies["email"].Value             = account.Email;
                        Response.Cookies["email"].Expires           = DateTime.UtcNow.AddDays(7);
                        Response.Cookies["gender"].Value            = student.Gender;
                        Response.Cookies["gender"].Expires          = DateTime.UtcNow.AddDays(7);
                        Response.Cookies["cbnvm"].Value             = "1";
                        Response.Cookies["cbnvm"].Expires           = DateTime.UtcNow.AddDays(7);
                        SendCongratulationsEmailToStudent(account.Email, account.FirstName);
                        return(RedirectToAction("Index", "StudentPortal"));
                    }
                    else if (account.ProfileType == "administrator")
                    {
                        string sessionkey = ClientSession.GetClientSessionKey("user", account.Email, account.FirstName + " " + account.LastName, "administrator");
                        Response.Cookies["sessionkey"].Value        = sessionkey;
                        Response.Cookies["sessionkey"].Expires      = DateTime.UtcNow.AddDays(7);
                        Response.Cookies["sessionusername"].Value   = account.Email;
                        Response.Cookies["sessionusername"].Expires = DateTime.UtcNow.AddDays(7);
                        Response.Cookies["cbnvm"].Value             = "1";
                        Response.Cookies["cbnvm"].Expires           = DateTime.UtcNow.AddDays(7);
                        SendCongratulationsEmailToAdmin(account.Email, account.FirstName + " " + account.LastName);
                        return(RedirectToAction("AddSchool", "AdminPortal"));
                    }
                    return(View());
                }
                else
                {
                    ViewBag.ErrorMessage = "No account found";
                }
            }
            return(RedirectToAction("LogIn"));
        }
Exemple #19
0
 /// <summary>
 /// 根据手机号查询用户信息
 /// </summary>
 /// <param name="phone"></param>
 /// <returns></returns>
 public static User GetUserByMobile(string phone)
 {
     using (var client = new UserAccountClient())
     {
         var serviceResult = client.GetUserByMobile(phone);
         serviceResult.ThrowIfException(true);
         return(serviceResult.Result);
     }
 }
        public ActionResult Search(string username, string faultID, string dateFrom, string dateTo)
        {
            if ((username != null || username != "") && (faultID == null || faultID == "") && (dateFrom == null || dateFrom == "") && (dateTo == null || dateTo == ""))
            {
                //WITH username

                Account account = new UserAccountClient().GetAccountByUsername(username);
                List<Fault> faultListWithAccount = new FaultClient().GetFaultsByAccountID(account.ID).ToList();

                foreach (Fault f in faultListWithAccount)
                {
                    List<FaultLog> flTemp = new FaultClient().GetAllFaultLogsByFaultID(f.ID).ToList();
                    foreach (FaultLog fl in flTemp)
                    {
                        faultLogList.Add(fl);
                    }
                }
            }
            else if ((username == null || username == "") && (faultID != null || faultID != "") && (dateFrom == null || dateFrom == "") && (dateTo == null || dateTo == ""))
            {
                //WITH faultID

                int fID = Convert.ToInt32(faultID);

                faultLogList = new FaultClient().GetAllFaultLogsByFaultID(fID).ToList();
            }
            else if ((username == null || username == "") && (faultID == null || faultID == "") && (dateFrom != null || dateFrom != "") && (dateTo != null || dateTo != ""))
            {
                //WITH DATES

                DateTime from = Convert.ToDateTime(dateFrom);
                DateTime to = Convert.ToDateTime(dateTo);

                faultLogList = new FaultClient().GetFaultLogsByDate(from, to).ToList();
            }
            else if ((username != null || !username.Equals("")) && (faultID != null || !faultID.Equals("")) && (dateFrom != null || !dateFrom.Equals("")) && (dateTo != null || !dateTo.Equals("")))
            {
                //ALL COMBINATIONS

                DateTime from = Convert.ToDateTime(dateFrom);
                DateTime to = Convert.ToDateTime(dateTo);
                int fID = Convert.ToInt32(faultID);

                Account account = new UserAccountClient().GetAccountByUsername(username);
                //List<Fault> faultListWithAccount = new FaultClient().GetFaultsByAccountID(account.ID).ToList();

                faultLogList = new FaultClient().GetFaultsByAllThreeCombinations(account.ID, fID, from, to).ToList();
            }
            else
            {
                //ERROR - CHOOSE EITHER ONE OR ALL.

                ModelState.AddModelError("", "Search must be done by either all three options, by username, by faultID, or by date-from and date-to.  Please enter the correct choice.");
            }

            return View("Index", faultLogList);
        }
        public async Task <ActionResult> GetAllVipCompany()
        {
            using (var client = new UserAccountClient())
            {
                var serviceReult = await client.SelectCompanyInfoByIdAsync(-1);

                serviceReult.ThrowIfException(true);
                return(Json(serviceReult.Result, JsonRequestBehavior.AllowGet));
            }
        }
Exemple #22
0
        private void ResendEmails()
        {
            UserAccountClient  uac   = new UserAccountClient();
            List <UserAccount> users = new List <UserAccount>(uac.GetAllNotConfirmEmails());

            foreach (UserAccount user in users)
            {
                SendVerificationEmail(user.RowKey, user.FirstName + " " + user.LastName);
            }
        }
 public ActionResult GetCompanyUsersByCompanyId(int companyId)
 {
     using (var client = new UserAccountClient())
     {
         var serviceResult = client.GetCompanyUsersByCompanyId(companyId);
         serviceResult.ThrowIfException(true);
         var companyUsers = serviceResult.Result;
         return(Json(companyUsers, JsonRequestBehavior.AllowGet));
     }
 }
 public ActionResult GetAllVipCompany()
 {
     using (var client = new UserAccountClient())
     {
         var serviceResult = client.SelectCompanyInfoById(-1);
         serviceResult.ThrowIfException(true);
         var allVipCompany = serviceResult.Result;
         return(Json(allVipCompany, JsonRequestBehavior.AllowGet));
     }
 }
        public ActionResult UpsertBeautyServicePackage(BeautyServicePackage package)
        {
            bool isSuccess = false;
            var  msg       = string.Empty;
            var  user      = HttpContext.User.Identity.Name;

            if (package != null && !string.IsNullOrEmpty(package.PackageName) && package.CooperateId > 0)
            {
                var manager       = new BankMRManager();
                var cooperateUser = manager.FetchMrCooperateUserConfigByPKID(package.CooperateId);
                if (cooperateUser != null)
                {
                    package.VipUserId = cooperateUser.VipUserId;
                    using (var client = new UserAccountClient())
                    {
                        var userServiceResult = client.SelectCompanyUserInfo(cooperateUser.VipUserId);
                        if (userServiceResult.Success && userServiceResult.Result != null)
                        {
                            package.VipUserName = userServiceResult.Result.UserName;
                            if (userServiceResult.Result.CompanyInfo != null)
                            {
                                package.VipCompanyId   = userServiceResult.Result.CompanyInfo.Id;
                                package.VipCompanyName = userServiceResult.Result.CompanyInfo.Name;
                            }
                        }
                    }
                }

                if (package.PKID > 0)
                {
                    package.UpdateUser = user;
                    isSuccess          = BeautyServicePackageManager.UpdateBeautyServicePackage(package);
                }
                else
                {
                    package.CreateUser = user;
                    isSuccess          = BeautyServicePackageManager.InsertBeautyServicePackage(package);
                }
                if (!isSuccess)
                {
                    msg = "更新失败";
                }
                else
                {
                    msg = "成功";
                }
            }
            else
            {
                msg = "信息不完善";
            }

            return(Json(new { IsSuccess = isSuccess, Msg = msg }, JsonRequestBehavior.AllowGet));
        }
        public static IEnumerable <SYS_CompanyUser> GetCompanyUsersByCompanyId(int companyId)
        {
            IEnumerable <SYS_CompanyUser> result = null;

            using (var client = new UserAccountClient())
            {
                var serviceResult = client.GetCompanyUsersByCompanyId(companyId);
                serviceResult.ThrowIfException(true);
                result = serviceResult.Result;
                return(result);
            }
        }
        public static User GetUserByMobile(string mobile)
        {
            User result = null;

            using (var client = new UserAccountClient())
            {
                var serviceResult = client.GetUserByMobile(mobile);
                serviceResult.ThrowIfException(true);
                result = serviceResult.Result;
                return(result);
            }
        }
        public static List <User> GetUsersByIds(List <Guid> userIds)
        {
            List <User> results = null;

            using (var client = new UserAccountClient())
            {
                var serviceResult = client.GetUsersByIds(userIds);
                serviceResult.ThrowIfException(true);
                results = serviceResult.Result;
                return(results);
            }
        }
        public static User GetUserById(Guid userId)
        {
            User result = null;

            using (var client = new UserAccountClient())
            {
                var serviceResult = client.GetUserById(userId);
                serviceResult.ThrowIfException(true);
                result = serviceResult.Result;
                return(result);
            }
        }
Exemple #30
0
        public static SYS_CompanyUser SelectCompanyUserInfo(Guid userId)
        {
            SYS_CompanyUser result = null;

            using (var client = new UserAccountClient())
            {
                var serviceResult = client.SelectCompanyUserInfo(userId);
                serviceResult.ThrowIfException(true);
                result = serviceResult.Result;
                return(result);
            }
        }
        /// <summary>
        /// 根据服务码查询服务码详情,有用户信息
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        public static async Task <Tuple <List <ServiceCodeDetail>, int> > GetServiceCodeDetailByCode(string code)
        {
            var result     = new List <ServiceCodeDetail>();
            var totalCount = 0;

            if (!string.IsNullOrEmpty(code))
            {
                var packageCodeDetails = GetBeautyServicePackageDetailCodesByCodes(new List <string>()
                {
                    code
                });
                var codeDetail = packageCodeDetails?.FirstOrDefault();
                totalCount = codeDetail != null ? 1 : 0;
                if (codeDetail != null)
                {
                    var codeDetails = await GetServiceCodeDetail(new List <string>() { code });

                    if (codeDetails != null && codeDetails.Any())
                    {
                        User user = null;
                        using (var client = new UserAccountClient())
                        {
                            var accountResult = await client.GetUserByIdAsync(codeDetail.UserId);

                            user = accountResult.Result;
                        }
                        foreach (var item in codeDetails)
                        {
                            item.Mobile = user?.MobileNumber;
                            result.Add(item);
                        }
                    }
                }
                if (!result.Any())
                {
                    var bankRecords = BankMRManager.GetBankMRActivityCodeRecordByServiceCode(new List <string>()
                    {
                        code
                    });
                    var bankMrServiceCodeDetails = await BankMRManager.SearchBankMRActivityCodeDetailByRecords(bankRecords);

                    if (bankMrServiceCodeDetails != null && bankMrServiceCodeDetails.Any())
                    {
                        result.AddRange(bankMrServiceCodeDetails);
                    }
                }
            }


            return(Tuple.Create(result, totalCount));
        }
Exemple #32
0
        protected void Application_AuthenticateRequest(object s, EventArgs e)
        {
            if (Context.User != null)
            {
                string name = Context.User.Identity.Name;
                IEnumerable<Common.Role> userRoles = new UserAccountClient().GetUserRoles(name).ToList();

                string[] arrayRoles = new string[userRoles.Count()];
                int count = 0;

                foreach (Common.Role r in userRoles)
                {
                    arrayRoles[count] = r.Name;
                    count++;
                }
                GenericPrincipal gp = new GenericPrincipal(Context.User.Identity, arrayRoles);
                Context.User = gp;
            }
        }
        public ActionResult ReportFault(GenerateFaultModel model, int pID)
        {
            try
            {
                if (Session["accountID"] != null)
                {
                    int ticketNumber;
                    bool available = false;

                    do
                    {
                        ticketNumber = new FaultClient().GenerateRandomNumber();
                        if (new FaultClient().GetFaultByTicketNumber(ticketNumber) != null)
                        {
                            ticketNumber = new FaultClient().GenerateRandomNumber();
                            available = false;
                        }
                        else
                        {
                            available = true;
                        }
                    }
                    while (!available);

                    BarCodeData barCodeData = new BarCodeData();
                    barCodeData.Height = 125;
                    barCodeData.Width = 225;
                    barCodeData.Angle = 0;
                    barCodeData.Ratio = 5;
                    barCodeData.Module = 0;
                    barCodeData.Left = 25;
                    barCodeData.Top = 0;
                    barCodeData.CheckSum = false;
                    barCodeData.FontName = "Arial";
                    barCodeData.BarColor = "Black";
                    barCodeData.BGColor = "White";
                    barCodeData.FontSize = 10.0f;
                    barCodeData.barcodeOption = BarcodeOption.Both;
                    barCodeData.barcodeType = BarcodeType.Code_2_5_interleaved;
                    barCodeData.checkSumMethod = CheckSumMethod.None;
                    barCodeData.showTextPosition = ShowTextPosition.BottomCenter;
                    barCodeData.BarCodeImageFormat = ImageFormats.PNG;

                    Byte[] imgBarcode = new BarCodeSoapClient().GenerateBarCode(barCodeData, randomNum.ToString());

                    MemoryStream memStream = new MemoryStream(imgBarcode);
                    Bitmap bm = new Bitmap(memStream);
                    bm.Save(HttpContext.Response.OutputStream, ImageFormat.Jpeg);

                    System.Drawing.Image image = System.Drawing.Image.FromStream(new System.IO.MemoryStream(imgBarcode));

                    Fault fault = new Fault();
                    fault.TicketNumber = ticketNumber;
                    fault.ProductID = pID;
                    fault.AccountID = (int)Session["accountID"];
                    fault.Barcode = imgBarcode;

                    new FaultClient().AddFault(fault);

                    FaultLog faultLog = new FaultLog();
                    faultLog.FaultID = new FaultClient().GetFaultByTicketNumber(ticketNumber).ID;
                    faultLog.Description = model.Description;
                    faultLog.DateOfReport = DateTime.Today;
                    faultLog.Status = "Reported";

                    new FaultClient().AddFaultLog(faultLog);
                    User user = new UserAccountClient().GetUserByAccountID((int)Session["accountID"]);

                    memStream.Position = 0;
                    string body = string.Format(@"Dear " + user.Name + " " + user.Surname + ",<br /><br />A new fault report has been made."+
                            "Please find attached your barcode image. <br />Ticket Number: " + ticketNumber + "<br /><br />Regards,<br />Electros Ltd. Staff");

                    //SEND EMAIL HERE
                    MailMessage newMessage = new MailMessage();

                    newMessage.From = new MailAddress("*****@*****.**");
                    newMessage.To.Add(new MailAddress(user.Email));
                    newMessage.Subject = "Fault Report";
                    newMessage.Attachments.Add(new Attachment(memStream, "Barcodeimg.jpg", "image/jpg"));
                    newMessage.IsBodyHtml = true;
                    newMessage.Body = body;
                    SmtpClient smtpClient = new SmtpClient("smtp.go.net.mt");
                    smtpClient.Send(newMessage);

                    return RedirectToAction("Index", "GenerateFault");
                }
                else
                {
                    return RedirectToAction("Login", "Login");
                }
            }
            catch (Exception e)
            {
                ViewBag.Error = "An error has occured.";
                return RedirectToAction("Index", "GenerateFault");
            }
        }
        public ActionResult Update(GenerateFaultModel model, int faultID)
        {
            try
            {
                if (Session["accountID"] != null)
                {
                    FaultLog faultLog = new FaultLog();

                    //faultLog.Status = model.Status;

                    int statusID = Convert.ToInt32(model.Status);
                    switch (statusID)
                    {
                        case 1:
                            faultLog.Status = "Reported";
                            sendSMS("Reported");
                            break;
                        case 2:
                            faultLog.Status = "Picked up - Transit to main office";
                            sendSMS("Picked up - Transit to main office");
                            break;
                        case 3:
                            faultLog.Status = "Service in progress";
                            sendSMS("Service in progress");
                            break;
                        case 4:
                            faultLog.Status = "Service completed - Ready for delivery";
                            sendSMS("Service completed - Ready for delivery");
                            break;
                        case 5:
                            faultLog.Status = "Picked up - Transit to customer";
                            sendSMS("Picked up - Transit to customer");
                            break;
                        case 6:
                            faultLog.Status = "Fault Completed";
                            sendSMS("Fault Completed");
                            break;
                        default:
                            faultLog.Status = "Reported";
                            sendSMS("Reported");
                            break;
                    }

                    faultLog.Description = model.Description;
                    faultLog.FaultID = faultID;
                    faultLog.DateOfReport = DateTime.Today;

                    new FaultClient().AddFaultLog(faultLog);
                    faultLogs.Add(faultLog);

                    Fault f = new FaultClient().GetFaultByID(faultID);

                    User u = new UserAccountClient().GetUserByAccountID(f.AccountID);

                    MailMessage newMessage = new MailMessage();
                    newMessage.From = new MailAddress("*****@*****.**");
                    newMessage.To.Add(new MailAddress(u.Email));
                    newMessage.Subject = "Fault Report";
                    newMessage.Body = "One of our representatives just updated your product with the latest service.  Please check our website for the update details.";
                    SmtpClient smtpClient = new SmtpClient("smtp.go.net.mt");
                    smtpClient.Send(newMessage);

                    return View("Index", faultLogs);
                }
                else
                {
                    return RedirectToAction("Login", "Login");
                }
            }
            catch (Exception e)
            {
                TempData["Error"] = "An error has occured.";
                return RedirectToAction("Index", faultLogs);
            }
        }
        public ActionResult Search(string username, string faultID, string dateFrom, string dateTo)
        {
            if (Session["accountID"] != null)
            {
                if ((username != null || username != "") && (faultID == null || faultID == "") && (dateFrom == null || dateFrom == "") && (dateTo == null || dateTo == ""))
                {
                    //WITH username
                    if (new UserAccountClient().GetAccountByUsername(username) != null)
                    {
                        Account account = new UserAccountClient().GetAccountByUsername(username);
                        List<Fault> faultListWithAccount = new FaultClient().GetFaultsByAccountID(account.ID).ToList();

                        foreach (Fault f in faultListWithAccount)
                        {
                            List<FaultLog> flTemp = new FaultClient().GetAllFaultLogsByFaultID(f.ID).ToList();
                            foreach (FaultLog fl in flTemp)
                            {
                                faultLogList.Add(fl);
                            }
                        }
                    }
                    else
                    {
                        TempData["Error"] = "Username doesn't exist.";
                        return RedirectToAction("Index", faultLogs);
                    }
                }
                else if ((username == null || username == "") && (faultID != null || faultID != "") && (dateFrom == null || dateFrom == "") && (dateTo == null || dateTo == ""))
                {
                    //WITH faultID

                    int fID = 0;

                    try
                    {
                        fID = Convert.ToInt32(faultID);
                    }
                    catch (Exception e)
                    {
                        TempData["Error"] = "No such fault ID was found.";
                        return RedirectToAction("Index", faultLogs);
                    }

                    if (new FaultClient().GetAllFaultLogsByFaultID(fID).ToList() != null)
                    {
                        faultLogList = new FaultClient().GetAllFaultLogsByFaultID(fID).ToList();
                    }
                    else
                    {
                        TempData["Error"] = "No such fault ID was found.";
                        return RedirectToAction("Index", faultLogs);
                    }
                }
                else if ((username == null || username == "") && (faultID == null || faultID == "") && (dateFrom != null || dateFrom != "") && (dateTo != null || dateTo != ""))
                {
                    //WITH DATES
                    try
                    {
                        DateTime from = Convert.ToDateTime(dateFrom);
                        DateTime to = Convert.ToDateTime(dateTo);

                        faultLogList = new FaultClient().GetFaultLogsByDate(from, to).ToList();
                    }
                    catch (Exception e)
                    {
                        TempData["Error"] = "Date format is incorrect.";
                        return RedirectToAction("Index", faultLogs);
                    }
                }
                else if ((username != null || !username.Equals("")) && (faultID != null || !faultID.Equals("")) && (dateFrom != null || !dateFrom.Equals("")) && (dateTo != null || !dateTo.Equals("")))
                {
                    //ALL COMBINATIONS

                    int fID = 0;

                    try
                    {
                        fID = Convert.ToInt32(faultID);
                    }
                    catch (Exception e)
                    {
                        TempData["Error"] = "No such fault ID was found.";
                        return RedirectToAction("Index", faultLogs);
                    }

                    if (new UserAccountClient().GetAccountByUsername(username) != null && new FaultClient().GetAllFaultLogsByFaultID(fID).ToList() != null)
                    {
                        DateTime from;
                        DateTime to;
                        try
                        {
                            from = Convert.ToDateTime(dateFrom);
                            to = Convert.ToDateTime(dateTo);
                        }
                        catch (Exception e)
                        {
                            TempData["Error"] = "Dates are not in the correct format.";
                            return RedirectToAction("Index", faultLogs);
                        }
                        int faID = Convert.ToInt32(faultID);

                        Account account = new UserAccountClient().GetAccountByUsername(username);

                        faultLogList = new FaultClient().GetFaultsByAllThreeCombinations(account.ID, faID, from, to).ToList();
                    }
                    else
                    {
                        TempData["Error"] = "Please enter correct data.";
                        return RedirectToAction("Index", faultLogs);
                    }
                }
                else
                {
                    ModelState.AddModelError("", "Search must be done by either all three options, by username, by faultID, or by date-from and date-to.  Please enter the correct choice.");
                }

                return View("Index", faultLogList);
            }
            else
            {
                return RedirectToAction("Login", "Login");
            }
        }
        public ActionResult ShowReport(int pID, int oID)
        {
            try
            {
                PrintStatementModel model = new PrintStatementModel();
                Order o = new OrderClient().GetOrderByID(oID);
                model.myOrder = o;

                ProductOrder po = new OrderClient().GetProductOrderByOrderIDAndProductID(o.ID, pID);
                model.myProductOrder = po;

                List<FaultLog> fl = new List<FaultLog>();

                Product p = new ProductClient().GetProductByID(pID);
                model.myProduct = p;

                List<Fault> f = new FaultClient().GetFaultsByAccountIDandProductID((int)Session["accountID"], pID).ToList();
                model.myFaultList = f;

                Common.FaultLog faultLog = new Common.FaultLog();
                List<Common.FaultLog> faultLogList = new List<Common.FaultLog>();
                List<Common.Fault> flist = new List<Common.Fault>();

                flist = new DSA_Assignment1_Sit1.FaultServ.FaultClient().GetFaultsByAccountIDandProductID((int)Session["accountID"], pID).ToList();

                foreach (Common.Fault fa in flist)
                {
                    List<Common.FaultLog> flTemp = new DSA_Assignment1_Sit1.FaultServ.FaultClient().GetAllFaultLogsByFaultID(fa.ID).ToList();

                    model.myFaultLog = flTemp;
                }

                if (model.myFaultLog == null)
                {
                    List<Order> orderList = new OrderClient().GetBoughtOrdersByAccountID((int)Session["accountID"]).ToList();

                    foreach (Order or in orderList)
                    {
                        List<ProductOrder> productOrderlist = new OrderClient().GetProductOrderByOrderID(or.ID).ToList();

                        foreach (ProductOrder por in productOrderlist)
                        {
                            allPO.Add(por);
                        }
                    }

                    ViewBag.Error = "No fault logs recorded.";
                    return RedirectToAction("PurchaseHistory", allPO);
                }
                //SEND EMAIL

                //get user email
                User user = new UserAccountClient().GetUserByAccountID((int)Session["accountID"]);

                //Render email

                Document document = new Document();
                MemoryStream memoryStream = new MemoryStream();
                PdfWriter writer = PdfWriter.GetInstance(document, memoryStream);

                document.Open();
                document.Add(new Paragraph("Electros Ltd."));
                document.Add(new Paragraph());
                document.Add(new Paragraph("Item: "));
                document.Add(new Paragraph("Product ID          " + "Name                    " + "Price          " + "Date Of Purchase         " + "Warranty Expiry"));
                document.Add(new Paragraph(model.myProduct.ID + "                    " + model.myProduct.Name + "          " + model.myProduct.Price + "          " + model.myOrder.DateOfOrder.ToShortDateString() + "             " + model.myProductOrder.WarrantyExpiry.ToShortDateString()));
                document.Add(new Paragraph());
                document.Add(new Paragraph("Faults: "));
                document.Add(new Paragraph("Fault ID          Date          Fault Details                              Status"));
                foreach (FaultLog flo in model.myFaultLog)
                {
                    document.Add(new Paragraph(flo.FaultID + "          " + flo.DateOfReport.ToShortDateString() + "          " + flo.Description + "                              " + flo.Status));
                }
                writer.CloseStream = false;
                document.Close();
                memoryStream.Position = 0;

                MailMessage newMessage = new MailMessage();
                newMessage.From = new MailAddress("*****@*****.**");
                newMessage.To.Add(new MailAddress(user.Email));
                newMessage.Subject = "Print Statement";
                newMessage.Body = "Dear " + user.Name + " " + user.Surname + ",  please find attached details of the product's faults.";
                Attachment attachment = new Attachment(memoryStream, "ReportStatement.pdf");
                newMessage.Attachments.Add(attachment);
                SmtpClient smtpClient = new SmtpClient("smtp.go.net.mt");
                smtpClient.Send(newMessage);

                return new RazorPDF.PdfResult(model, "ShowReport");
            }
            catch (Exception e)
            {
                List<Order> orderList = new OrderClient().GetBoughtOrdersByAccountID((int)Session["accountID"]).ToList();

                foreach (Order o in orderList)
                {
                    List<ProductOrder> productOrderlist = new OrderClient().GetProductOrderByOrderID(o.ID).ToList();

                    foreach (ProductOrder po in productOrderlist)
                    {
                        allPO.Add(po);
                    }
                }
                ViewBag.Error = "An error has occured.";
                return RedirectToAction("PurchaseHistory" , allPO);
            }
        }
        public ActionResult Update(GenerateFaultModel model, int faultID)
        {
            FaultLog faultLog = new FaultLog();
            faultLog.Status = model.Status;
            faultLog.Description = model.Description;
            faultLog.FaultID = faultID;
            faultLog.DateOfReport = DateTime.Today;

            new FaultClient().AddFaultLog(faultLog);
            faultLogs.Add(faultLog);

            Fault f = new FaultClient().GetFaultByID(faultID);

            User u = new UserAccountClient().GetUserByAccountID(f.AccountID);

            MailMessage newMessage = new MailMessage();
            newMessage.From = new MailAddress("*****@*****.**");
            newMessage.To.Add(new MailAddress(u.Email));
            newMessage.Subject = "Fault Report";
            newMessage.Body = "One of our representatives just updated your product with the latest service.  Please check our website for the update details.";
            SmtpClient smtpClient = new SmtpClient("smtp.go.net.mt");
            smtpClient.Send(newMessage);

            return View("Index", faultLogs);
        }