public JsonResult QuestionUpdate(AskOperation askOperation) { AskDto ask = askOperation.ask; string operation = askOperation.Operation; ChatIntentQuestion question = new ChatIntentQuestion(); bool changed = false; ask.UpdatedDate = DateTime.UtcNow; try { if (operation == "a") { question.QuestionDesc = ask.QuestionDesc; question.ChatIntentId = ask.ChatIntentId; question.UpdatedDate = DateTime.Now; db.ChatIntentQuestion.Add(question); } else if (operation == "u") { question = db.ChatIntentQuestion.Where(x => x.QuestionId == ask.QuestionId).FirstOrDefault(); question.QuestionDesc = ask.QuestionDesc; question.ChatIntentId = ask.ChatIntentId; question.UpdatedDate = DateTime.Now; } else { question = db.ChatIntentQuestion.Where(x => x.QuestionId == ask.QuestionId).FirstOrDefault(); db.ChatIntentQuestion.Attach(question); db.ChatIntentQuestion.Remove(question); } changed = true; db.SaveChanges(); return(Json(changed, JsonRequestBehavior.AllowGet)); } catch (Exception e) { Console.WriteLine(e.Message); return(Json(changed, JsonRequestBehavior.AllowGet)); } }
public static AskDto Map(AskDto askDto, Pergunta pergunta) { askDto.Code = (Models.Enums.EnumQuestion)pergunta.Codigo; askDto.Answer = pergunta.Resposta.Equals("S") ? "S" : "N"; return(askDto); }
public static Pergunta Map(Pergunta pergunta, AskDto askDto) { pergunta.Codigo = (int)askDto.Code; pergunta.Resposta = askDto.Answer?.Equals("S") ?? false; return(pergunta); }