コード例 #1
0
        public async Task <ActionResult> _TagSettingsModal(int?tagID)
        {
            if (tagID == null)
            {
                TempData["GeneralError"] = "tagId was null.";
                return(RedirectToAction("Index"));
            }
            RuuviTagModel tag = await db.RuuviTagModels.FindAsync(tagID);

            if (tag == null)
            {
                TempData["GeneralError"] = "Tag not found.";
                return(RedirectToAction("Index"));
            }
            string userID = User.Identity.GetUserId();

            if (tag.UserId != userID)
            {
                TempData["GeneralError"] = "You don't have access to that tag.";
                return(RedirectToAction("Index"));
            }
            ViewBag.AvailableGroups = await GetAvailableGroupsForTag(tagID, userID);

            return(PartialView(tag));
        }
コード例 #2
0
        public async Task <ActionResult> _TagSettingsModal([Bind(Include = "TagId,TagMacAddress,TagActive,TagName,UserId")] RuuviTagModel tag)
        {
            TempData["ReturnToTag"] = tag.TagId;
            if (ModelState.IsValid)
            {
                if (!string.IsNullOrWhiteSpace(tag.TagName) && await TagNameTakenAsync(User.Identity.GetUserId(), tag.TagName, tag.TagId))
                {
                    TempData["TagErrorList"] = new List <string> {
                        "Couldn't change tag name, since you already have a tag with that name!"
                    };
                    TempData["ShowTagSettings"] = true;
                    TempData["TagModel"]        = tag;
                    return(RedirectToAction("Index"));
                }
                db.Entry(tag).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            TempData["TagErrorList"]    = ModelState.Values.SelectMany(v => v.Errors).Select(e => e.ErrorMessage).ToList();
            TempData["ShowTagSettings"] = true;
            TempData["TagModel"]        = tag;
            return(RedirectToAction("Index"));
        }
コード例 #3
0
        public async Task <ActionResult> DeleteTag(int tagid)
        {
            RuuviTagModel tag = await db.RuuviTagModels.FindAsync(tagid);

            if (User.Identity.GetUserId() != tag.UserId)
            {
                TempData["GeneralError"] = "You don't have access to that tag.";
                return(RedirectToAction("Index"));
            }
            db.RuuviTagModels.Remove(tag);
            await db.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
コード例 #4
0
        public async Task <ActionResult> LoggedInApiData(int?tagID, int?interval)
        {
            if (tagID == null)
            {
                TempData["GeneralError"] = "Something went wrong while fetching data. Please try again";
                return(RedirectToAction("Index"));
            }
            RuuviTagModel tag = db.RuuviTagModels.Find(tagID);

            if (tag == null)
            {
                TempData["GeneralError"] = "Something went wrong while fetching data. Please try again";
                return(RedirectToAction("Index"));
            }
            if (tag.UserId != User.Identity.GetUserId())
            {
                TempData["GeneralError"] = "You do not have permission to do that.";
                return(RedirectToAction("Index"));
            }
            List <WhereOSApiRuuvi> apiResponse;

            if (interval != null)
            {
                apiResponse = await GetTagData(tag.TagMacAddress, (int)interval);
            }
            else
            {
                apiResponse = await GetTagData(tag.TagMacAddress);
            }

            List <UnpackData> lstapiData = new List <UnpackData>();

            foreach (WhereOSApiRuuvi apiRuuviTag in apiResponse)
            {
                UnpackData    ApiRowData = new UnpackData();
                UnpackRawData RawDataRow = new UnpackRawData();
                RawDataRow.UnpackAllData(apiRuuviTag.data);
                ApiRowData.Data = RawDataRow;
                ApiRowData.Time = apiRuuviTag.time;
                lstapiData.Add(ApiRowData);
            }


            return(Json(lstapiData, JsonRequestBehavior.AllowGet));
        }