internal void ServiceUpdate(string baseHost) { //1 - Lấy giờ TblUpdate lastUpdate = GetClientLastUpdate(); //2 - Kéo về var data = GetUpdateConsultants(baseHost, lastUpdate.LastConsutantUpdate.Value); //3 - Cập Nhập if (data != null && data.Count() > 0) { // update foreach (var item in data) { if (item.IsDeleted.Value == 0) { InsertOrUpdate(item); } else { Delete(item); } } } //4 - Lấy ra var postData = GetAll().Where(x => x.UpdateDate >= lastUpdate.LocalConsutantUpdate.Value).ToList(); DateTime updateDate = DateTime.Now; //5 - Đẩy lên var res = PostUpdateToServer(baseHost, postData); //6 - Lưu giờ if (res.Success) { BBLUpdate upData = new BBLUpdate(); TblUpdate u = upData.GetCurrent(); if (u == null) { u = new TblUpdate(); DateTime mindate = DateTime.Parse("2000/01/01"); u.LastActivityLogUpdate = mindate; u.LastUserUpdate = mindate; u.LastConsutantUpdate = res.UpdateDate; u.LastInfoUpdate = mindate; u.LastUserPermissionUpdate = mindate; u.LastClientUpdate = mindate; u.LocalClientUpdate = mindate; u.LocalActivityLogUpdate = mindate; u.LocalInfoUpdate = mindate; u.LocalUserUpdate = mindate; u.LocalConsutantUpdate = updateDate; } else { u.LastConsutantUpdate = res.UpdateDate; u.LocalConsutantUpdate = updateDate; } upData.Update(u); } }
private void resetUpdateToolStripMenuItem_Click(object sender, EventArgs e) { DateTime mindate = DateTime.Parse("2000/01/01"); BBLUpdate u = new BBLUpdate(); var up = u.GetCurrent(); up.LastActivityLogUpdate = mindate; up.LastClientUpdate = mindate; up.LastConsutantUpdate = mindate; up.LastInfoUpdate = mindate; up.LastUserUpdate = mindate; up.LastUserPermissionUpdate = mindate; up.LocalActivityLogUpdate = mindate; up.LocalClientUpdate = mindate; up.LocalConsutantUpdate = mindate; up.LocalInfoUpdate = mindate; up.LocalUserUpdate = mindate; u.Update(up); }
static bool PostUpdateClients(string uri, DateTime date) { try { HttpClient client = new HttpClient(); client.BaseAddress = new Uri(uri); client.DefaultRequestHeaders.Accept.Add( new MediaTypeWithQualityHeaderValue("application/json")); BBLClient clientData = new BBLClient(); var postData = clientData.GetAll().Where(x => x.UpdateDate >= date); var response = client.PostAsJsonAsync("api/Update/UpdateClients", postData).Result; response.EnsureSuccessStatusCode(); if (response.IsSuccessStatusCode) { APIResult data = response.Content.ReadAsAsync<APIResult>().Result; if (data.Success == true) { BBLUpdate upData = new BBLUpdate(); TblUpdate u = upData.GetCurrent(); if (u == null) { u = new TblUpdate(); DateTime mindate = DateTime.Parse("2000/01/01"); u.LastActivityLogUpdate = mindate; u.LastClientUpdate = DateTime.Now; u.LastConsutantUpdate = mindate; u.LastInfoUpdate = mindate; u.LastUserPermissionUpdate = mindate; u.LastUserUpdate = mindate; } else { u.LastClientUpdate = DateTime.Now; } upData.Update(u); } return true; } else { return false; } } catch (Exception) { return false; } }