// mark task from the task queue as complete public JsonResult MarkTaskAsComplete(int assetId, string alertMsg, string tName, string tAssignee) { try { bool isComplete = CheckIfTaskComplete(assetId); if (isComplete == true) { return(Json(new { errorCompleting = false, wasComplete = true, message = "The task you selected has already been marked complete. Please select another task." })); } else { // get current user (user resolving the task) var user = User.FindFirst(ClaimTypes.NameIdentifier).Value; var userDetails = _dbcontext.Users.Where(x => x.Id == user).FirstOrDefault(); string resolvingUser = userDetails.UserName; // create modified task object TaskQueue modifiedTask = new TaskQueue(); modifiedTask.AssetId = assetId; modifiedTask.isComplete = true; modifiedTask.resolvedBy = resolvingUser; modifiedTask.dateComplete = DateTime.Now; modifiedTask.alertMessage = alertMsg; modifiedTask.Name = tName; modifiedTask.assignee = tAssignee; _dbcontext.Update(modifiedTask); _dbcontext.SaveChanges(); return(Json(new { errorCompleting = false, wasComplete = false, message = "Successfully marked task as complete." })); } } catch (Exception ex) { // EVENTUALLY LOG EXCEPTION return(Json(new { errorCompleting = true, message = "An error occured while marking the task complete. Please try again or contact a system admin." })); } }
public JsonResult DeleteAsset(int assetId, string name, string shortDescription, string longDescription, Boolean isPreferredAsset, string assetType, string assetOwner) { try { var findAssetType = _dbcontext.AssetTypes.Where(x => x.typeID == Convert.ToInt32(assetType)).FirstOrDefault(); Asset deletedAsset = new Asset(); deletedAsset.AssetId = assetId; deletedAsset.AssetName = name; deletedAsset.ShortDescription = shortDescription; deletedAsset.LongDescription = longDescription; deletedAsset.Owner = assetOwner; if (findAssetType == null) { deletedAsset.typeName = null; } else { deletedAsset.typeName = findAssetType.typeName; } deletedAsset.isDeleted = true; // delete asset from user's preferred assets SaveUsersPreferredAsset(assetId, true); _dbcontext.Update(deletedAsset); _dbcontext.SaveChanges(); return(Json(new { isDeleted = true, message = "Successfully deleted " + name + "." })); } catch (Exception ex) { // EVENTUALLY LOG EXCEPTION return(Json(new { isDeleted = false, message = "An error occured while attempting to delete " + name + ". Please try again or contact a system admin." })); } }