public APIResult UpdateInfor(TblInfor data) { APIResult res = new APIResult(); using (Sonartez_server db = new Sonartez_server(connectionString)) { var matchedObj = (from c in db.TblInfor where c.ID == data.ID select c).SingleOrDefault(); if (matchedObj == null) { try { // does not exist Table<TblInfor> TblObj = db.TblInfor; data.ServerUpdate = DateTime.Now; TblObj.InsertOnSubmit(data); TblObj.Context.SubmitChanges(); res.UpdateDate = data.ServerUpdate.Value; res.Success = true; } catch (Exception ex) { res.Message = ex.Message; res.Success = false; } } else { try { matchedObj.BeginDate = data.BeginDate; matchedObj.CreateDate = data.CreateDate; matchedObj.CreateUserID = data.CreateUserID; matchedObj.ExprieDate = data.ExprieDate; matchedObj.InfoContent = data.InfoContent; matchedObj.InfoTag = data.InfoTag; matchedObj.InfoTitle = data.InfoTitle; matchedObj.InfoType = data.InfoType; matchedObj.Status = data.Status; matchedObj.UpdateDate = data.UpdateDate; matchedObj.ServerUpdate = DateTime.Now; db.SubmitChanges(); res.UpdateDate = data.ServerUpdate.Value; res.Success = true; } catch (Exception ex) { res.Message = ex.Message; res.Success = false; } } } return res; }
public APIResult UpdateUser(TblUser data) { APIResult res = new APIResult(); using (Sonartez_server db = new Sonartez_server(connectionString)) { var matchedObj = (from c in db.TblUser where c.UserID == data.UserID select c).SingleOrDefault(); if (matchedObj == null) { try { // does not exist Table<TblUser> TblObj = db.TblUser; data.ServerUpdate = DateTime.Now; TblObj.InsertOnSubmit(data); TblObj.Context.SubmitChanges(); res.UpdateDate = data.ServerUpdate.Value; res.Success = true; } catch (Exception ex) { res.Message = ex.Message; res.Success = false; } } else { try { matchedObj.Active = data.Active; matchedObj.Email = data.Email; matchedObj.FullName = data.FullName; matchedObj.LastLoginTime = data.LastLoginTime; matchedObj.Password = data.Password; matchedObj.PhoneNumber = data.PhoneNumber; matchedObj.UserName = data.UserName; matchedObj.ServerUpdate = DateTime.Now; matchedObj.UpdateDate = data.UpdateDate; db.SubmitChanges(); res.UpdateDate = data.UpdateDate.Value; res.Success = true; } catch (Exception ex) { res.Message = ex.Message; res.Success = false; } } } return res; }
public APIResult UpdateConsultantLog(TblConsultantLog data) { APIResult res = new APIResult(); using (Sonartez_server db = new Sonartez_server(connectionString)) { var matchedObj = (from c in db.TblConsultantLog where c.ID == data.ID select c).SingleOrDefault(); if (matchedObj == null) { try { // does not exist Table<TblConsultantLog> TblObj = db.TblConsultantLog; data.ServerUpdate = DateTime.Now; TblObj.InsertOnSubmit(data); TblObj.Context.SubmitChanges(); res.UpdateDate = data.ServerUpdate.Value; res.Success = true; } catch (Exception ex) { res.Message = ex.Message; res.Success = false; } } else { try { matchedObj.AnswerRef = data.AnswerRef; matchedObj.ClientCode = data.ClientCode; matchedObj.ClientID = data.ClientID; matchedObj.ClientName = data.ClientName; matchedObj.ConsType = data.ConsType; matchedObj.CreateDate = data.CreateDate; matchedObj.Descriptions = data.Descriptions; matchedObj.FinishDate = data.FinishDate; matchedObj.FinishType = data.FinishType; matchedObj.Question = data.Question; matchedObj.Status = data.Status; matchedObj.SubmitDate = data.SubmitDate; matchedObj.TargetCount = data.TargetCount; matchedObj.TargetCountry = data.TargetCountry; matchedObj.TargetEmail = data.TargetEmail; matchedObj.TargetName = data.TargetName; matchedObj.TargetPhoneNumber = data.TargetPhoneNumber; matchedObj.TargetType = data.TargetType; matchedObj.UserID = data.UserID; matchedObj.UserName = data.UserName; matchedObj.ServerUpdate = DateTime.Now; matchedObj.UpdateDate = data.UpdateDate; db.SubmitChanges(); res.UpdateDate = data.ServerUpdate.Value; res.Success = true; } catch (Exception ex) { res.Message = ex.Message; res.Success = false; } } } return res; }
public APIResult UpdateClient(TblUserPermission data) { APIResult res = new APIResult(); using (Sonartez_server db = new Sonartez_server(connectionString)) { var matchedObj = (from c in db.TblUserPermission where c.ID == data.ID select c).SingleOrDefault(); if (matchedObj == null) { try { // does not exist Table<TblUserPermission> TblObj = db.TblUserPermission; data.ServerUpdate = DateTime.Now; TblObj.InsertOnSubmit(data); TblObj.Context.SubmitChanges(); res.UpdateDate = data.ServerUpdate.Value; res.Success = true; } catch (Exception ex) { res.Message = ex.Message; res.Success = false; } } else { try { matchedObj.PermissionID = data.PermissionID; matchedObj.PermissionName = data.PermissionName; matchedObj.UserID = data.UserID; matchedObj.ServerUpdate = DateTime.Now; matchedObj.UpdateTime = data.UpdateTime; db.SubmitChanges(); res.UpdateDate = data.UpdateTime.Value; res.Success = true; } catch (Exception ex) { res.Message = ex.Message; res.Success = false; } } } return res; }
public APIResult UpdateClients(IEnumerable<TblClient> dataList) { APIResult res = new APIResult(); using (Sonartez_server db = new Sonartez_server(connectionString)) { foreach (var data in dataList) { var matchedObj = (from c in db.TblClient where c.ClientID == data.ClientID select c).SingleOrDefault(); if (matchedObj == null) { try { // does not exist Table<TblClient> TblObj = db.TblClient; data.ServerUpdate = DateTime.UtcNow; TblObj.InsertOnSubmit(data); TblObj.Context.SubmitChanges(); res.UpdateDate = DateTime.UtcNow; res.Success = true; } catch (Exception ex) { res.Message = ex.Message; res.Success = false; break; } } else { try { matchedObj.ClientCode = data.ClientCode; matchedObj.ClientName = data.ClientName; matchedObj.Descriptions = data.Descriptions; matchedObj.LocationCode = data.LocationCode; matchedObj.LocationName = data.LocationName; matchedObj.ServerUpdate = DateTime.UtcNow; matchedObj.UpdateDate = data.UpdateDate.Value; db.SubmitChanges(); res.UpdateDate = DateTime.UtcNow; res.Success = true; } catch (Exception ex) { res.Message = ex.Message; res.Success = false; break; } } } } return res; }
public APIResult UpdateActivityLog(TblActivityLog data) { APIResult res = new APIResult(); using (Sonartez_server db = new Sonartez_server(connectionString)) { var matchedObj = (from c in db.TblActivityLog where c.ID == data.ID select c).SingleOrDefault(); if (matchedObj == null) { try { // does not exist Table<TblActivityLog> TblObj = db.TblActivityLog; data.ServerUpdate = DateTime.UtcNow; TblObj.InsertOnSubmit(data); TblObj.Context.SubmitChanges(); res.UpdateDate = DateTime.UtcNow; res.Success = true; } catch (Exception ex) { res.Message = ex.Message; res.Success = false; } } else { try { matchedObj.ActivityType = data.ActivityType; matchedObj.ClientName = data.ClientName; matchedObj.Descriptions = data.Descriptions; matchedObj.ClientID = data.ClientID; matchedObj.UserID = data.UserID; matchedObj.UserName = data.UserName; matchedObj.CreateDate = data.CreateDate; matchedObj.ServerUpdate = DateTime.UtcNow; db.SubmitChanges(); res.UpdateDate = DateTime.UtcNow; res.Success = true; } catch (Exception ex) { res.Message = ex.Message; res.Success = false; } } } return res; }
internal APIResult PostUpdateToServer(string uri, IEnumerable<TblConsultantLog> postData) { APIResult data = new APIResult() { Message = "Error", Success = false, UpdateDate = DateTime.Parse("2000/01/01") }; try { HttpClient client = new HttpClient(); client.BaseAddress = new Uri(uri); client.DefaultRequestHeaders.Accept.Add( new MediaTypeWithQualityHeaderValue("application/json")); var response = client.PostAsJsonAsync("api/Update/UpdateConsultantLogs", postData).Result; response.EnsureSuccessStatusCode(); if (response.IsSuccessStatusCode) { data = response.Content.ReadAsAsync<APIResult>().Result; } return data; } catch (Exception ex) { data.Message = ex.Message; return data; } }