public HttpResponseMessage SaveFiles() { var httpRequest = HttpContext.Current.Request; if (httpRequest.Files.Count > 0) { foreach (string file in httpRequest.Files) { var postedFile = httpRequest.Files[file]; var filePath = HttpContext.Current.Server.MapPath("~/Images/" + postedFile.FileName); postedFile.SaveAs(filePath); if (m_id != -1) { using (var ctx = new PicardDb()) { Dishes d = ctx.m_dishes.FirstOrDefault(i => i.Id == m_id); d.ImageSrc = "/Images/" + postedFile.FileName; ctx.Entry(d).State = EntityState.Modified; ctx.SaveChanges(); } } else { m_id = -1; return(Request.CreateResponse(HttpStatusCode.BadRequest)); } } m_id = -1; return(Request.CreateResponse(HttpStatusCode.Created)); } m_id = -1; return(Request.CreateResponse(HttpStatusCode.BadRequest)); }
public MainController() { if (m_motor == null) { try { PhidgetMotor.MotorCallback p = new PhidgetMotor.MotorCallback(MotorFunctionCallback); m_motor = new GojiMotor(p); m_sendWatch.Restart(); using (var ctx = new PicardDb()) { List <AppConfig> data = (from r in ctx.m_appConfig select r).ToList(); m_motor.SetMotorLength(data[0].MotorLength); m_motor.MaxLength = data[0].MaxLength; m_motor.MinLength = data[0].MinLength; m_motor.SetPrecisionOnStop(0.25f); } } catch (Exception err) { Console.WriteLine(err.Message); } } }
public string UpdateDish(JObject data) { try { Dishes d = new Dishes(); dynamic json1 = data; d.Name = json1.Name; d.Id = json1.Id; d.ImageSrc = json1.ImageSrc; d.Script = json1.Script; d.AlphaConstant = json1.AlphaConstant; string time = json1.TimeToRun; string[] s = time.Split(':'); d.TimeToRun = new TimeSpan(0, int.Parse(s[0]), int.Parse(s[1])); using (var ctx = new PicardDb()) { ctx.Entry(d).State = EntityState.Modified; ctx.SaveChanges(); return(getAllDishes()); } } catch (Exception err) { return(getAllDishes()); } }
public string CreateNewDish(JObject data) { Dishes d = new Dishes(); dynamic json1 = data; d.Name = json1.dishname; d.ImageSrc = json1.imagesrc; d.TimeToRun = json1.TimeToRun; d.Script = json1.script; d.AlphaConstant = json1.AlphaConstant; string time = json1.TimeToRun; string[] s = time.Split(':'); d.TimeToRun = new TimeSpan(0, int.Parse(s[0]), int.Parse(s[1])); using (var ctx = new PicardDb()) { ctx.Entry(d).State = EntityState.Added; ctx.SaveChanges(); ctx.Entry(d).GetDatabaseValues(); int id = d.Id; return(id.ToString()); } }
public string GetAppConfig() { using (var ctx = new PicardDb()) { IEnumerable <AppConfig> data = from r in ctx.m_appConfig orderby r.Id ascending select r; JavaScriptSerializer jss = new JavaScriptSerializer(); string json = jss.Serialize(data); return(json); } }
public string getAllDishes() { using (var ctx = new PicardDb()) { IEnumerable <Dishes> data = from r in ctx.m_dishes orderby r.Id ascending select r; JavaScriptSerializer jss = new JavaScriptSerializer(); string json = jss.Serialize(data); return(json); } }
public string getDishById(int id) { using (var ctx = new PicardDb()) { IEnumerable <Dishes> result = from r in ctx.m_dishes where r.Id == id select r; JavaScriptSerializer jss = new JavaScriptSerializer(); string json = jss.Serialize(result); return(json); } }
public string deleteDishById(int id) { using (var ctx = new PicardDb()) { var result = (from r in ctx.m_dishes where r.Id == id select r).ToList(); ctx.Entry(result[0]).State = EntityState.Deleted; ctx.SaveChanges(); return(getAllDishes()); } }
public string SetMotorLength(int length) { if (length < 1 || length > 99) { return(GetAppConfig()); } AppConfig d = new AppConfig(); d.MotorLength = length; using (var ctx = new PicardDb()) { ctx.Entry(d).State = EntityState.Modified; ctx.SaveChanges(); MainController.getMotorControl().SetMotorLength(length); return(GetAppConfig()); } }
public string SaveAppConfig(JObject data) { //var context = GlobalHost.ConnectionManager.GetHubContext<ChatHub>(); //context.Clients.All.ShowMessage("eee"); try { int id = 1; using (var ctx = new PicardDb()) { var query = (from r in ctx.m_appConfig select r).First(); id = (int)query.Id; } dynamic json = data; using (var ctx = new PicardDb()) { AppConfig a = new AppConfig(); a.Id = id; a.MotorLength = json.MotorLength; a.MaxLength = json.MaxLength; a.MinLength = json.MinLength; ctx.Entry(a).State = EntityState.Modified; ctx.SaveChanges(); MainController.getMotorControl().SetMotorLength(a.MotorLength); MainController.getMotorControl().MaxLength = a.MaxLength; MainController.getMotorControl().MinLength = a.MinLength; } } catch (Exception err) { Console.WriteLine(err.Message); } return(GetAppConfig()); }