public JsonResult Register(TaiKhoanViewModel TaikhoanVm) { try { if (!ModelState.IsValid) { IEnumerable <ModelError> allErrors = ModelState.Values.SelectMany(v => v.Errors); return(Json(allErrors, JsonRequestBehavior.AllowGet)); } else { var s = UtilityFunction.RandomString(6, false); _userService.Register(TaikhoanVm, s); if (TaikhoanVm.KeyId == 0) { if (TaikhoanVm.email == "") { return(Json(new { Result = const_Error.EXISTED_EMAIL, Status = "FAIL" }, JsonRequestBehavior.AllowGet)); } if (TaikhoanVm.sdt == "") { return(Json(new { Result = const_Error.EXISTED_SDT, Status = "FAIL" }, JsonRequestBehavior.AllowGet)); } } else { string MailContent = System.IO.File.ReadAllText(Server.MapPath("/Models/template.html")); MailContent = MailContent.Replace("{{Code}}", s); new MailHelper().SendMail(TaikhoanVm.email, "Register Code", MailContent); if (_userService.Save()) { return(Json(new { Result = TaikhoanVm, Status = "OK" }, JsonRequestBehavior.AllowGet)); } } } Response.StatusCode = (int)HttpStatusCode.BadRequest; return(Json(new { Result = Response, Status = "FAIL" }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { Response.StatusCode = (int)HttpStatusCode.BadRequest; return(Json(new { Result = ex.Message, Status = "FAIL" }, JsonRequestBehavior.AllowGet)); } }