/// <summary> /// Updates the account. /// </summary> /// <param name="account">The account.</param> /// <returns></returns> public bool UpdateAccount(Account account) { try { lock (lockObject) { var path = GetAccountPath(account.Name); if (File.Exists(path)) { using (var sw = File.CreateText(path)) { var ser = new JavaScriptSerializer(); sw.Write(ser.Serialize(account)); } } else { return false; } } } catch (Exception) { return false; } return true; }
public HttpResponseMessage Post(Account account) { try { var res = _accountService.UpdateAccount(account); return Request.CreateResponse(HttpStatusCode.OK, res); } catch (Exception ex) { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex.Message); } }
/// <summary> /// Ensures the data store. This will create a JSON file for every account configured in the web.config /// </summary> private void EnsureDataStore() { lock (lockObject) { var types = ConfigurationManager.AppSettings["accountTypes"].Split(';'); foreach (var t in types) { var path = GetAccountPath(t); if (File.Exists(path)) { continue; } var a = new Account { Name = t }; using (var sw = File.CreateText(path)) { var ser = new JavaScriptSerializer(); sw.Write(ser.Serialize(a)); } } } }