public void TestGetLogsResponse() { IVcRestClient client = Substitute.For <IVcRestClient>(); client.Request(Arg.Any <Request>()) .Returns(new Response( HttpStatusCode.OK, "{\"last_key\":\"\",\"log_items\":[{\"account_id\":\"10000\",\"account_id_item_id\":\"10000-+13109999999\",\"account_id_log_type\":\"10000-number.purchased\",\"account_id_operator_id\":\"10000-10000\",\"description\":\"numberpurchased\",\"item_id\":\"+13109999999\",\"item_type\":\"number\",\"log_data\":{\"phone_number\":\"+113109999999\"},\"log_data_json\":\"{\\\"phone_number\\\":\\\"+13109999999\\\"}\",\"log_id\":\"33340905951207340072784104845492921599137333898341842944\",\"log_timestamp\":20170517215209876172,\"log_type\":\"number.purchased\",\"operator_id\":\"10000\",\"operator_type\":\"account\",\"origin\":\"system\"},{\"account_id\":\"10000\",\"account_id_item_id\":\"10000-+13109999999\",\"account_id_log_type\":\"10000-number.create\",\"account_id_operator_id\":\"10000-00\",\"description\":\"chargenumber\",\"item_id\":\"+13109999999\",\"item_type\":\"local\",\"log_data\":{\"number\":\"+13109999999\",\"number_type\":\"local\"},\"log_data_json\":\"{\\\"number_type\\\":\\\"local\\\",\\\"number\\\":\\\"+13109999999\\\"}\",\"log_id\":\"33340905945476048556761734697849912190563694622780293120\",\"log_timestamp\":20170517215209619776,\"log_type\":\"number.create\",\"operator_id\":\"10000\",\"operator_type\":\"number\",\"origin\":\"system\"}]}" )); DateTime startTime = new DateTime(2017, 5, 16); DateTime endTime = new DateTime(2017, 5, 18); AccountLogs logs = Account.GetLogs(startTime, endTime, client: client); Assert.NotNull(logs); }
private async Task ExecuteLoadHomepage() { try { if (NetworkStatus.IsInternet()) { using (HttpClient client = new HttpClient()) { client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", Convert.ToBase64String(Common.SERVICE_CREDENTIALS)); using (HttpResponseMessage response = await client.GetAsync(Common.GET_GET_MED_TAKE_TODAY(PersistentSettings.AccountID))) { if (response.IsSuccessStatusCode) { var jData = await response.Content.ReadAsStringAsync(); if (!string.IsNullOrWhiteSpace(jData)) { GetMedTakeTodayResult result = JsonConvert.DeserializeObject <GetMedTakeTodayResult>(jData); if (result != null) { UpcomingMedTakes.Clear(); foreach (var item in result.results) { UpcomingMedTakes.Add(item); } } } } } using (HttpResponseMessage response = await client.GetAsync(Common.GET_GET_ACCOUNT_LOGS(PersistentSettings.AccountID))) { if (response.IsSuccessStatusCode) { var jData = await response.Content.ReadAsStringAsync(); if (!string.IsNullOrWhiteSpace(jData)) { GetAccountLogsResult result = JsonConvert.DeserializeObject <GetAccountLogsResult>(jData); if (result.results != null) { AccountLogs.Clear(); foreach (var item in result.results) { AccountLogs.Add(item); } } } } } } } else { await Common.ShowMessageAsyncNetworkError(); } } catch (Exception error) { await Common.ShowMessageAsyncApplicationError(error.Message); } finally { IsBusy = false; } }
public async Task <IActionResult> Create([Bind("Id,FirstName,LastName,BirthDay,Phone")] AccountInfomation accountInfomation, int[] classIds, int roleId) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var Rnb = ""; switch (roleId) { case 1: Rnb = "A"; break; case 2: Rnb = "M"; break; case 3: Rnb = "D"; break; default: return(BadRequest()); } //Generate RollNumber var count = await _context.Account.CountAsync(a => a.RollNumber.Contains(Rnb)) + 1; string rollNumber; if (count < 10) { rollNumber = "0000" + count; } else if (count < 100) { rollNumber = "000" + count; } else if (count < 1000) { rollNumber = "00" + count; } else if (count < 10000) { rollNumber = "0" + count; } else { rollNumber = count.ToString(); } var rnber = (Rnb + rollNumber).ToLower(); // Generate Email var str = accountInfomation.FirstName.Split(" "); string email = accountInfomation.LastName; foreach (var item in str) { if (item.Any()) { email += item[0]; } } email = email.ToLower(); var emailGenerate = RemoveUTF8.RemoveSign4VietnameseString(email + rnber + "@siingroup.com").ToLower(); var passwordGenerate = RemoveUTF8.RemoveSign4VietnameseString(email + rnber); //Create new account Account account = new Account { RollNumber = rnber, Email = emailGenerate, Salt = PasswordHandle.GetInstance().GenerateSalt() }; account.Password = PasswordHandle.GetInstance().EncryptPassword(passwordGenerate, account.Salt); _context.Account.Add(account); //Create thông tin đăng nhập để trả về response Login login = new Login { Email = emailGenerate, Password = passwordGenerate }; //Check uniqe by phone if (AccountExistsByPhone(accountInfomation.Phone)) { return(Conflict("Tài khoản đã tồn tại trên hệ thống, vui lòng kiểm tra lại!")); } else { //Save account await _context.SaveChangesAsync(); //Get ra account.Id để gán cho FK ownerId bên accountinfomation accountInfomation.OwnerId = account.Id; _context.AccountInfomation.Add(accountInfomation); await _context.SaveChangesAsync(); AccountLogsDefault log = new AccountLogsDefault { Title = "Đã tạo tài khoản với email " + login.Email + "!" }; _context.Default.Add(log); AccountLogs al = new AccountLogs { OwnerId = account.Id, CreatedBy = accountInfomation.FirstName + " " + accountInfomation.LastName, Default = log }; _context.Log.Add(al); await _context.SaveChangesAsync(); foreach (var item in classIds) { Classes classes = new Classes { OwnerId = account.Id, ClassId = item }; _context.Classes.Add(classes); AccountLogsDefault logs = new AccountLogsDefault(); var classAccount = _context.Class.SingleOrDefault(a => a.Id == classes.ClassId); logs.Title = accountInfomation.FirstName + " " + accountInfomation.LastName + " đã xếp bạn vào lớp " + classAccount.Name; _context.Default.Add(logs); AccountLogs als = new AccountLogs { OwnerId = account.Id, CreatedBy = accountInfomation.FirstName + " " + accountInfomation.LastName, Default = logs }; _context.Log.Add(als); } await _context.SaveChangesAsync(); } return(Created("", login)); }