public ActionResult Register(User item) { if (ModelState.IsValid) { try { if (db1.User.Any(u => u.email == item.email)) { ModelState.AddModelError("Email", "Email address already exists. Please change email address."); return(View(item)); } var qRCodeModel = GenerateQRCode(item.email); WebClient myWebClient = new WebClient(); try { string pdfPath = Server.MapPath(qRCodeModel.QRCodeImagePath); Response.ContentType = "iamges/jpeg"; Response.AppendHeader("content-disposition", "attachment; filename=" + item.email + ".jpg"); Response.TransmitFile(pdfPath); Response.End(); //myWebClient.DownloadFile(Server.MapPath(qRCodeModel.QRCodeImagePath), Server.MapPath(qRCodeModel.QRCodeImagePath)); } catch (Exception e) { TempData["result_code"] = -1; TempData["message"] = "An error occured"; TempData.Keep(); ModelState.AddModelError("Exception", "QR code can't downloaded. Updade your browser before."); return(View(item)); } db1.User.Add(item); db1.SaveChanges(); Models.SecondModel.User user2 = new Models.SecondModel.User(); user2.full_name = item.full_name; user2.status = true; user2.password = item.password; user2.code = qRCodeModel.QRCodeText; user2.reduction = Convert.ToDecimal(QRCodeModel.randomDouble(0, 1)); db2.User.Add(user2); db2.SaveChanges(); TempData["result_code"] = 1; TempData["message"] = "Account created successfully"; TempData.Keep(); return(RedirectToAction("Index", "Home")); } catch (Exception e) { TempData["result_code"] = -1; TempData["message"] = "An error occured"; TempData.Keep(); ModelState.AddModelError("Exception", e.Message); return(View(item)); } } TempData["result_code"] = -1; TempData["message"] = "Datas not valid"; TempData.Keep(); ModelState.AddModelError("Exception", "Datas not valid"); return(View(item)); }