public void Evaluate() { // Arrange FormEvaluationModel evaluation = new FormEvaluationModel { customer = new Customer(), Evaluation = new Evaluation() }; evaluation.customer.idCustomer = "*****@*****.**"; evaluation.customer.nameCustomer = "Juan Perez"; evaluation.customer.regDate = DateTime.Now; evaluation.Evaluation.idService = 1; evaluation.Evaluation.evalDate = DateTime.Now; evaluation.Evaluation.score = 8; Repository oRepo = new Repository(); ServiceResponse response = new ServiceResponse(); // Act response = oRepo.insertScore(evaluation); // Assert Assert.AreEqual(false, response.success); }
public ActionResult Index() { FormEvaluationModel oModel = new FormEvaluationModel(); Repository oRepo = new Repository(); var response = oRepo.getServices(); if (response.success) { oModel.services = response.services; return(View(oModel)); } else { return(Json(new { msj = response.message }, JsonRequestBehavior.AllowGet)); } }
public ActionResult Evaluate(FormEvaluationModel evaluation) { Repository oRepo = new Repository(); var response = oRepo.insertScore(evaluation); if (response.success) { FormEvaluationModel oModel = new FormEvaluationModel(); oModel.services = response.services; return(PartialView("Index", oModel)); } else { return(Json(new { msj = response.message }, JsonRequestBehavior.AllowGet)); } }
public ServiceResponse insertScore(FormEvaluationModel evaluation) { ServiceResponse oServiceResponse = new ServiceResponse(); evaluation.Evaluation.evalDate = DateTime.Now; if (_dbContext != null) { try { var evalDate = evaluation.Evaluation.evalDate.Date; var existScoreDate = _dbContext.Evaluation.Any(x => x.idCustomer == evaluation.customer.idCustomer && x.evalDate == evalDate && x.idService == evaluation.Evaluation.idService); if (existScoreDate) { oServiceResponse.success = false; oServiceResponse.message = evaluation.customer.nameCustomer + ", ud. ya realizó una evaluación del servicio el día de hoy " + evaluation.Evaluation.evalDate.ToString("dd/MM/yyyy") + ", puede volver a realizarlo el día de mañana "; return(oServiceResponse); } else { if (!_dbContext.Customer.Any(x => x.idCustomer == evaluation.customer.idCustomer)) { evaluation.customer.regDate = DateTime.Now; var insCustomer = _dbContext.Customer.Add(evaluation.customer); insCustomer.Evaluation.Add(evaluation.Evaluation); _dbContext.SaveChanges(); oServiceResponse.services = gettingServices(); oServiceResponse.success = true; oServiceResponse.message = "Evaluación registrada, gracias!."; return(oServiceResponse); } else { var customer = _dbContext.Customer.Find(evaluation.customer.idCustomer); customer.Evaluation.Add(evaluation.Evaluation); _dbContext.SaveChanges(); oServiceResponse.services = gettingServices(); oServiceResponse.success = true; oServiceResponse.message = "Evaluación registrada, gracias!."; return(oServiceResponse); } } } catch (Exception e) { oServiceResponse.success = false; oServiceResponse.message = "Error: " + e.Message; return(oServiceResponse); } finally { _dbContext.Dispose(); } } else { oServiceResponse.success = false; oServiceResponse.message = "No se puede acceder a la base de datos, contactarse con el administrador."; return(oServiceResponse); } }