// 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 UpdateName(string firstname, string lastname) { bool success = false; try { if (ModelState.IsValid) { var user = User.FindFirst(ClaimTypes.NameIdentifier).Value; var userDetails = _dbcontext.Users.Where(x => x.Id == user).FirstOrDefault(); // assumption is only one input field in User Profile screen is getting changed at a time. if (!String.IsNullOrEmpty(firstname)) { userDetails.FirstName = firstname; } else if (!String.IsNullOrEmpty(lastname)) { userDetails.LastName = lastname; } _dbcontext.Users.Update(userDetails); _dbcontext.SaveChanges(); success = true; } } catch (DbUpdateException) { ModelState.AddModelError("", "Unable to save updated user profile changes to database."); success = false; } catch (Exception) { ModelState.AddModelError("", "Some general exception occured other than db update exception."); success = false; } if (success) { return(Json(new { success = true, responseText = "Update successful." })); } else { return(Json(new { success = false, responseText = "Update failed." })); } }
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." })); } }