public bool Insert(HealthyInformation healthyInformation) { if (healthyInformation != null) { healthyInformation.CreateDate = DateTime.Now; } var newInformation = _healthyEntities.HealthyInformation.Add(healthyInformation); _healthyEntities.SaveChanges(); return(newInformation != null ? true : false); }
public ActionResult Post(int?heartBeat, int?oxy, int?userID) { try { if (heartBeat == null || oxy == null || userID == null) { return(Json("Error", JsonRequestBehavior.AllowGet)); } var healthyInformation = new HealthyInformation { HeartBeat = heartBeat.Value, Oxy = oxy.Value, UserID = userID.Value }; var resultInsert = _healthyInformationRepository.Insert(healthyInformation); if (resultInsert) { var listHealthyInformationTemp = new List <HealthyInformation>(); var listResult = _healthyInformationRepository.GetHealthyInformationByUsername(Session["UserName"]?.ToString()); for (int i = 0; i < listResult.Count; i++) { listHealthyInformationTemp.Add(new HealthyInformation { CreateDate = listResult[i].CreateDate, HeartBeat = listResult[i].HeartBeat, ID = listResult[i].ID, Oxy = listResult[i].Oxy, UserID = listResult[i].UserID }); } UpdateHealthyCare(listHealthyInformationTemp); if (heartBeat != null && (heartBeat > 110 || heartBeat < 40)) { _accountService.SendSMS(userID ?? 0); } return(Json("Success", JsonRequestBehavior.AllowGet)); } } catch (Exception ex) { return(Json(ex.Message, JsonRequestBehavior.AllowGet)); } return(Json("Fail", JsonRequestBehavior.AllowGet)); }