public async Task <IHttpActionResult> ChangeCheck(int id) { var finFeed = (from a in db.feedbacks where a.id == id select a).FirstOrDefault(); if (finFeed != null) { if (finFeed._checked == true) { return(Ok(await GetFeedbackAsync())); } else if (finFeed._checked == false) { finFeed._checked = true; db.Entry(finFeed).State = System.Data.Entity.EntityState.Modified; await db.SaveChangesAsync(); return(Ok(await GetFeedbackAsync())); } else { return(Ok(await GetFeedbackAsync())); } } else { return(BadRequest("Not found.")); } }
public async Task <IHttpActionResult> Putfaq(int id, faq faq) { var findFAQs = await db.faqs.Where(a => a.id == id).FirstOrDefaultAsync(); if (findFAQs != null) { findFAQs.title = faq.title; findFAQs.body = faq.body; db.Entry(findFAQs).State = EntityState.Modified; int check = await db.SaveChangesAsync(); if (check > 0) { return(Ok(await db.faqs.ToListAsync())); } else { return(BadRequest("Update fails.")); } } else { return(BadRequest("FAQs not found.")); } }
public async Task <IHttpActionResult> CreateFaculty([FromBody] faculty form) { try { //find duplicate faculty code var faculty = db.faculties.Where(a => a.faculty_code.ToString().ToUpper() == form.faculty_code.ToString().ToUpper()).FirstOrDefault(); if (faculty == null) { form.create_at = DateTime.Now; db.Entry(form).State = System.Data.Entity.EntityState.Added; int check = await db.SaveChangesAsync(); if (check > 0) { return(Ok(await ListFaculty())); } else { return(BadRequest("Create faculty error")); } } else { return(BadRequest("Duplicate faculty")); } } catch { return(BadRequest("Error")); } }
public async Task <IHttpActionResult> DeleteSurveys(int id) { try { var findSurvey = db.surveys.Where(a => a.id == id && a.deleted == false).FirstOrDefault(); if (findSurvey != null) { findSurvey.deleted = true; db.Entry(findSurvey).State = System.Data.Entity.EntityState.Modified; int check = await db.SaveChangesAsync(); if (check > 0) { return(Ok("Deleted successful.")); } else { return(BadRequest("Deleted fails.")); } } else { return(BadRequest("Surveys not found.")); } } catch { return(BadRequest("Error.")); } }
public async Task <IHttpActionResult> UpdateAskChoice(int idQuestion, int idAnswer, [FromBody] question_choice form) { var findQuestion = (from a in db.questions where a.id == idQuestion select a).FirstOrDefault(); if (findQuestion != null) { var answers = db.question_choice.Where(a => a.id == idAnswer && a.question_id == findQuestion.id).FirstOrDefault(); if (answers != null) { var answer_title = db.question_choice .Where(a => a.description.ToString().ToLower() == form.description.ToString().ToLower() && a.id != idAnswer).FirstOrDefault(); if (answer_title == null) { answers.description = form.description; db.Entry(answers).State = System.Data.Entity.EntityState.Modified; int check = await db.SaveChangesAsync(); if (check > 0) { return(Ok(await FetchDetailsSurvey.GetDetailsSurvey(Convert.ToInt32(findQuestion.surveys_id)))); } else { return(BadRequest("Update ask error.")); } } else { return(BadRequest("Answer duplicate")); } } else { return(BadRequest("Asks for question not found.")); } } else { return(BadRequest("Question not found.")); } }
public async Task <IHttpActionResult> ResetPassword(int id, [FromBody] ResetAccount form) { try { var account = (from a in db.accounts where a.id == id select a).FirstOrDefault(); if (account != null) { //check same password var pass1 = HashPassword.hashPassword(form.password); var pass2 = HashPassword.hashPassword(form.pre_password); if (pass1 == pass2) { account.password = pass1; account.password2 = pass2; int val = await db.SaveChangesAsync(); //search from list report var findListReport = db.report_account.Where(a => a.account_id == account.id).FirstOrDefault(); if (findListReport != null) { db.Entry(findListReport).State = System.Data.Entity.EntityState.Deleted; await db.SaveChangesAsync(); } if (val > 0) { return(Ok(await FetchDetailsAccount.GetDetailsAccount(id))); } else { return(BadRequest("Reset password error.")); } } else { return(BadRequest("Passwords are not the same.")); } } else { return(BadRequest("Not found accounts.")); } }catch (Exception e) { return(BadRequest(e.Message)); } }
public async Task <IHttpActionResult> CreateSurveysResponse(int idSurvey) { //find and check username var identity = (ClaimsIdentity)User.Identity; var username = identity.Claims.Where(a => a.Type == ClaimTypes.Name).Select(c => c.Value).FirstOrDefault(); var findUser = db.accounts.Where(a => a.username == username).FirstOrDefault(); if (findUser != null) { //find survey with date start less than current date var findSurvey = db.surveys.Where(a => a.id == idSurvey && a.date_start <= DateTime.Now && a.deleted == false && a.publish == true).FirstOrDefault(); if (findSurvey != null) { //find this user joined if not join create else update var findMessage = db.surveys_response.Where(a => a.surveys_id == idSurvey && a.accounts_id == findUser.id).FirstOrDefault(); if (findMessage == null) { surveys_response form = new surveys_response(); form.surveys_id = findSurvey.id; form.accounts_id = findUser.id; form.create_at = DateTime.Now; form.username = username; db.surveys_response.Add(form); int check = await db.SaveChangesAsync(); if (check > 0) { return(Ok(await FetchDetailsSurvey.GetDetailsSurvey(findSurvey.id))); } else { return(BadRequest("Create fails.")); } } else { findMessage.create_at = DateTime.Now; db.Entry(findMessage).State = System.Data.Entity.EntityState.Modified; int check = await db.SaveChangesAsync(); if (check > 0) { return(Ok(await FetchDetailsSurvey.GetDetailsSurvey(findSurvey.id))); } else { return(BadRequest("update fails.")); } } } else { return(BadRequest("Survey not found.")); } } else { return(BadRequest("Account not found.")); } }