public async Task fileIsActive(int projectID, int fileID, string newStatus) { stringToBool isValidInput = new stringToBool(); isValidInput = projectMethod.stringToBool(newStatus); if (!isValidInput.isBool) { await Context.Channel.SendMessageAsync("T/F Input is invalid try **true** or **false**"); return; } using (var dbContext = new SqliteDbContext()) { var list = dbContext.Files.Where(x => x.ProjectId == projectID && x.FileId == fileID); if (list.Count() < 1) { await Context.Channel.SendMessageAsync("target file does not exist, please ensure the input is correct"); } //input is false/0 change incomplete back to false if (isValidInput.value) { dbContext.Projects.Where(x => x.ProjectId == projectID).FirstOrDefault().isComplete = false; } var item = list.FirstOrDefault(); item.isActive = isValidInput.value; item.LastUpdated = DateTime.Now; await Context.Channel.SendMessageAsync("File status updated"); await dbContext.SaveChangesAsync(); } }
public async Task projectiscomplete(int projectID, string newStatus) { stringToBool isValidInput = new stringToBool(); isValidInput = projectMethod.stringToBool(newStatus); if (!isValidInput.isBool) { await Context.Channel.SendMessageAsync("T/F Input is invalid try **true** or **false**"); return; } using (var dbContext = new SqliteDbContext()) { if (dbContext.Projects.Where(x => x.ProjectId == projectID).Count() < 1) { await Context.Channel.SendMessageAsync("The project do not exist, maybe is a wrong ID"); } var item = dbContext.Projects.Where(x => x.ProjectId == projectID).FirstOrDefault(); //if user is not the owner, return if (item.UserId != Context.User.Id) { var owner = dbContext.Users.Where(x => x.UserId == item.UserId).FirstOrDefault(); await Context.Channel.SendMessageAsync($"You are not **{owner.UserName}**, please contach owner to remove project!"); return; } else if (!projectMethod.allFileInactive(projectID)) { await Context.Channel.SendMessageAsync("Some files are still active, please set to active to false and try again!"); return; } else { item.isComplete = (isValidInput.value); await dbContext.SaveChangesAsync(); await Context.Channel.SendMessageAsync($"Project: **{item.ProjectName}** successfully updated"); } } }