protected void btn_Register_Click(object sender, EventArgs e) { CMACGMEntities1 db = new CMACGMEntities1(); var manager = Context.GetOwinContext().GetUserManager <ApplicationUserManager>(); var user = new ApplicationUser() { UserName = Email.Text, Email = Email.Text }; var signInManager = Context.GetOwinContext().Get <ApplicationSignInManager>(); var manage = manager.FindByEmail(Email.Text); if (manage == null) { IdentityResult result = manager.Create(user, Password.Text); if (result.Succeeded) { AdminProfile newAdmin = new AdminProfile(); signInManager.SignIn(user, isPersistent: false, rememberBrowser: false); newAdmin.FirstName = tb_firstName.Text; newAdmin.FirstName = tb_lastName.Text; newAdmin.AspNetUserId = user.Id; db.AdminProfiles.Add(newAdmin); db.SaveChanges(); //IdentityHelper.RedirectToReturnUrl(Request.QueryString["ReturnUrl"], Response); Response.Redirect("~/Login.aspx"); } else { ErrorMessage.Text = result.Errors.FirstOrDefault(); } } else { ErrorMessage.Text = "Provided email address is already registered. Please Enter a different email address."; } }
protected void btn_Submit_Click(object sender, EventArgs e) { CMACGMEntities1 db = new CMACGMEntities1(); //check validations Query newData = new Query(); if (tb_BookingRef.Text != "") { newData.BookingReference = tb_BookingRef.Text; } if (tb_LaraPartnerCode.Text != "") { newData.LaraPartnerCode = tb_LaraPartnerCode.Text; } if (tb_Voyage.Text != "") { newData.Voyage = tb_Voyage.Text; } if (ddl_Ports.SelectedIndex != 0 && ddl_Ports.SelectedValue != "") { //find port id if (tb_BookingRef.Text != "" && tb_LaraPartnerCode.Text != "" && tb_Voyage.Text != "" && fileUploader.HasFile) { CMACGM.Port selectedPort = new CMACGM.Port(); if (db.Ports.Any(a => a.Name == ddl_Ports.SelectedValue)) { selectedPort = db.Ports.Where(a => a.Name == ddl_Ports.SelectedValue).First(); } newData.Port = selectedPort; if (fileUploader.HasFile) { string Extension = Path.GetExtension(fileUploader.PostedFile.FileName); if (Extension == ".png" && Extension == ".jpeg" && Extension == ".jpg" && Extension == ".txt" && Extension == ".TXT" && Extension == ".doc" && Extension == ".docx") { try { string filename = Path.GetFileName(fileUploader.FileName); string filePath = CargoUtil.filePath + ddl_Ports.SelectedValue + "/"; bool exists = System.IO.Directory.Exists(filePath); if (!exists) { System.IO.Directory.CreateDirectory(filePath); } fileUploader.SaveAs(filePath + filename); newData.AttachedFilePath = filename; lbl_UploadStatus.Visible = true; ClearFields(); } catch (Exception ex) { ScriptManager.RegisterStartupScript(this, typeof(Page), "text", "alert('Upload status: The file could not be uploaded. Please try again');", true); } } } try { newData.UserID = 1.ToString(); db.Queries.Add(newData); db.SaveChanges(); ScriptManager.RegisterStartupScript(this, typeof(Page), "text", "alert('Form submitted successfully!');", true); } catch (Exception ex) { ScriptManager.RegisterStartupScript(this, typeof(Page), "text", "alert('Something went wrong , Please try again!');", true); } } } else { ScriptManager.RegisterStartupScript(this, typeof(Page), "text", "alert('Please Select Port');", true); } }