public ActionResult Deactivate(TagHistory tagHistory, int id, DeactivateModel deactivateModel) { var db = DAL.DbContext.Create(); var studentToDeactivate = db.Students.Get(id); if (studentToDeactivate.Id <= 0) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } DateTime today = DateTime.Today; if (ModelState.IsValid) { tagHistory.StudentID = studentToDeactivate.Id; tagHistory.DeactivationDate = today; tagHistory.DeactivatedTag = studentToDeactivate.EPC; tagHistory.DeactivationReasonID = deactivateModel.DeactivationReasonID; db.TagHistorys.Insert(tagHistory); //set EPC to null studentToDeactivate.EPC = " "; //Update db.Students EPC to null db.Students.Update(studentToDeactivate.Id, studentToDeactivate); return(RedirectToAction("UpdateEPC", new { id = id })); } ViewBag.DeactivationReasonID = new SelectList(db.DeactivationReason.All(), "Id", "Reason", tagHistory.DeactivationReasonID); return(RedirectToAction("Details", new { id = id })); }
/// <summary> ///This method will 'undo' a key activation with a certain machine code. ///The key should not be blocked, since otherwise this method will throw an error. /// https://app.cryptolens.io/docs/api/v3/Deactivate /// </summary> /// <param name="token">The access token. Read more at https://app.cryptolens.io/docs/api/v3/Auth </param> /// <param name="parameters">The parameters that the method needs.</param> /// <returns>A <see cref="BasicResult"/> or null.</returns> /// <example> /// <code language="csharp" title="Deactivation example"> /// var auth = "{access token with permission to access the deactivate method}" /// var result = Key.Deactivate(token: auth, parameters: new DeactivateModel() /// { /// Key = "GEBNC-WZZJD-VJIHG-GCMVD", /// ProductId = 3349, /// MachineCode = SKGL.SKM.getMachineCode(SKGL.SKM.getSHA1); /// }); /// /// if(result == null || result.Result == ResultType.Error) /// { /// // could not deactivate. maybe it has already been deactivated. /// // more information can be found in the message. /// } /// /// // everything went fine if we are here! /// </code> /// </example> public static BasicResult Deactivate(string token, DeactivateModel parameters) { if (parameters != null) { if (parameters.OSInfo == null) { try { parameters.OSInfo = Helpers.GetOSStats(); } catch { } } else if (parameters.OSInfo == "") { parameters.OSInfo = null; } } return(HelperMethods.SendRequestToWebAPI3 <BasicResult>(parameters, "/key/deactivate/", token)); }
public ActionResult Deactivate(TagHistory tagHistory, int id, DeactivateModel deactivateModel) { var db = DAL.DbContext.Create(); var studentToDeactivate = db.Students.Get(id); if (studentToDeactivate.Id <= 0) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } DateTime today = DateTime.Today; if (ModelState.IsValid) { tagHistory.StudentID = studentToDeactivate.Id; tagHistory.DeactivationDate = today; tagHistory.DeactivatedTag = studentToDeactivate.EPC; tagHistory.DeactivationReasonID = deactivateModel.DeactivationReasonID; db.TagHistorys.Insert(tagHistory); //set EPC to null studentToDeactivate.EPC = " "; //Update db.Students EPC to null db.Students.Update(studentToDeactivate.Id, studentToDeactivate); return RedirectToAction("UpdateEPC", new { id = id }); } ViewBag.DeactivationReasonID = new SelectList(db.DeactivationReason.All(), "Id", "Reason", tagHistory.DeactivationReasonID); return RedirectToAction("Details", new { id = id }); }
/// <summary> ///This method will 'undo' a key activation with a certain machine code. ///The key should not be blocked, since otherwise this method will throw an error. /// https://app.cryptolens.io/docs/api/v3/Deactivate /// </summary> /// <param name="token">The access token. Read more at https://app.cryptolens.io/docs/api/v3/Auth </param> /// <param name="parameters">The parameters that the method needs.</param> /// <returns>A <see cref="BasicResult"/> or null.</returns> /// <example> /// <code language="csharp" title="Deactivation example"> /// var auth = "{access token with permission to access the deactivate method}" /// var result = Key.Deactivate(token: auth, parameters: new DeactivateModel() /// { /// Key = "GEBNC-WZZJD-VJIHG-GCMVD", /// ProductId = 3349, /// MachineCode = SKGL.SKM.getMachineCode(SKGL.SKM.getSHA1); /// }); /// /// if(result == null || result.Result == ResultType.Error) /// { /// // could not deactivate. maybe it has already been deactivated. /// // more information can be found in the message. /// } /// /// // everything went fine if we are here! /// </code> /// </example> public static BasicResult Deactivate(string token, DeactivateModel parameters) { return(HelperMethods.SendRequestToWebAPI3 <BasicResult>(parameters, "/key/deactivate/", token)); }