public async Task<ActionResult> Register(UserAccount account) { if (ModelState.IsValid) { //use these for IP and date time account.MyIPAddress = Request.UserHostAddress; //more ip checks are needed DateTime time = DateTime.Now; // Use current time. account.MyDateTime = time.ToString(); using (OurDBContext db = new OurDBContext()) { db.userAccount.Add(account); db.SaveChanges(); await SendAsyncMail(account.FirstName, account.LastName, account.Email); WriteExcel(time, account.MyIPAddress, account.FirstName, account.LastName, account.Email); } ModelState.Clear(); ViewBag.Message = account.FirstName + " " + account.LastName + " successfully registered."; } else { ViewBag.Message = "Unable to create."; } return View(); }
public ActionResult Index() { using (OurDBContext db = new OurDBContext()) { // var persona = new Persona() {Usuario = "Aura", Password = "******", Id = 78 }; // db.Padres.Add(new Padre() { Telefono = 11111, Nombre = "Domingo", Persona = persona}); //db.Personas.Add(persona); //db.SaveChanges(); // db.cuentas.Add(model); // db.SaveChanges(); var categoria = new Categoria() { Name = "Name" }; db.Productos.Add(new Producto() { Categoria = categoria, CategoryId1 = 200, Name = "ok", ProductId = 2 }); db.Categorias.Add(categoria); db.SaveChanges(); } return(View()); }
public ActionResult Definir(int id, int exp, DateTime[] selectedDatas) { UserAccountExposicao userAccountExposicao = _db.UserAccountExposicao.Find(id, exp); if (userAccountExposicao != null) { if (selectedDatas != null) { foreach (var data in selectedDatas) { Disponibilidade disponibilidade = new Disponibilidade { DataDisponibilidade = data, ExposicaoID = exp, UserAccountID = id }; _db.Disponibilidade.Add(disponibilidade); } _db.SaveChanges(); return(RedirectToAction("PerfilUser", "Account", new { id = id })); } return(RedirectToAction("Definir", new { id = id, exp = exp })); } return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); }
public ActionResult Register(Candidates candidate) { if (ModelState.IsValid) { using (OurDBContext db = new OurDBContext()) { db.candidateAccount.Add(candidate); db.SaveChanges(); } //send a registration email once changes are saved in the database CustomEmail regMail = new CustomEmail(); regMail.sendMail(candidate.Email, "Select International Registration", "Welcome to our platform!"); ModelState.Clear(); ViewBag.Message = candidate.FirstName + "" + candidate.LastName + "registration done"; //sending request to external vendor and other XML part handled here //if this is successful, need to make changes in UploadFileController too //should we do this async? using (OurDBContext db = new OurDBContext()) { Candidates cand1 = db.candidateAccount.Single(g => g.UserName == candidate.UserName); string clientCode = cand1.Requestor; Client client = db.clientAccount.Find(clientCode); RequestController rc = new RequestController(); rc.AssessmentOrderRequest(clientCode, client.ProviderKey, client.CustomerNumber, "test01", candidate.UserID, client.CallBackUri, candidate.LastName, candidate.FirstName, candidate.Email); } } return(View()); }
public ActionResult Registro(Cuenta model) { //Si el modelo es valido if (ModelState.IsValid) { using (OurDBContext db = new OurDBContext()) { Boolean tik = false; string nombreLocal = model.User; //aqui verificamos que el nombre que ingreso en la vista no exista en la DB foreach (var item in db.cuentas) { if (nombreLocal == item.User) { tik = true; } } //aqui verificamos que hacer en caso de que el tik sea true o falso, //o sea, en caso de que existe el usario en la DB si o no if (tik) { ViewBag.Message = model.User + " Error: Esta persona existe en l DB"; } else { ViewBag.Message = model.User + " Bienvenido"; db.cuentas.Add(model); db.SaveChanges(); } } } return(View()); }
//guarda na bd a marcação em questão public override void SalvarBd(OurDBContext db) { TimeSpan dur = TimeSpan.Parse(exposicao.Duracao.Hour + ":" + exposicao.Duracao.Minute); marcacao.HoraDeFim = marcacao.HoraDeInicio.Add(dur); db.Marcacao.Add(marcacao); db.SaveChanges(); }
public ActionResult Register(Candidates candidate) { if (ModelState.IsValid) { // New workflow: // 1. Send XML request and check OK or Not, get urls info // 2. Store all info(candidatw) + urls // 3. Configure email content and send // 4. Need to this in batch register as well string id = candidate.UserID; //tianyi's code is filled here. //List<string> urls = new List<string>(); //urls.Add("http1"); //urls.Add("http2"); //urls.Add("http3"); // Sending XML request and retieve urls using (var db = new OurDBContext()) { var client = db.clientAccount.Find(candidate.Requestor); if (client != null) { var request = new RequestController(); ReturnType returnType = request.AssessmentOrderRequest(client, candidate, "Test pool 1", "None call back"); db.candidateAccount.Add(candidate); db.candidateProgressList.Add(new CandidateProgress { ReciptID = returnType.ReceiptId, UserID = id, AssessmentURL = returnType.Url, Progress = "0" //initialize progress as 0 }); db.SaveChanges(); //var progress = db.candidateProgressList.Last(); //Console.Write("URL: "+progress.AssessmentURL); //send a registration email once changes are saved in the database CustomEmail regMail = new CustomEmail(); StringBuilder mailMessage = new StringBuilder(); mailMessage.Append("Hi, " + candidate.FirstName + ":\n"); mailMessage.Append("Welcome to our platform! The followings are the assessments you need to take:\n"); mailMessage.Append(returnType.Url + "\n"); mailMessage.Append("Good Luck!"); regMail.sendMail(candidate.Email, "Select International Registration", mailMessage.ToString()); ModelState.Clear(); ViewBag.Message = candidate.FirstName + "" + candidate.LastName + "registration done"; } } } return(View()); }
public ActionResult Edit([Bind(Include = "MarcacaoID,NomeRequerente,Idade,NumTelefoneRequerente,Data,HoraDeInicio,HoraDeFim,NumPessoas,ExposicaoID,UserAccountID")] Marcacao marcacao) { if (ModelState.IsValid) { Exposicao exposicao = db.Exposicao.Find(marcacao.ExposicaoID); if (dbMuseu.DataExposicaoMarcacao(marcacao.Data, exposicao.DataInicial, exposicao.DataFinal)) { TimeSpan dur = TimeSpan.Parse(exposicao.Duracao.Hour + ":" + exposicao.Duracao.Minute); marcacao.HoraDeFim = marcacao.HoraDeInicio.Add(dur); db.Entry(marcacao).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Edit", "Marcacao", new { id = marcacao.MarcacaoID })); } ModelState.AddModelError("Data", "Esta Exposição occore de " + exposicao.DataInicial.ToShortDateString() + " a " + exposicao.DataFinal.ToShortDateString()); } UserAccountDropdownListMarcacao(marcacao.ExposicaoID, marcacao.MarcacaoID, marcacao.UserAccount); return(View(marcacao)); }
//Alterar o estado da candidatura na base de dados para 2 (VerificarCandidatura) ou cria uma nova com o estado a 2 public void SubmeterDb(UserAccountExposicao userAccountExposicao) { var submeterCandidatura = db.UserAccountExposicao.Where(u => u.UserAccountID == userAccountExposicao.UserAccountID).SingleOrDefault(u => u.ExposicaoID == userAccountExposicao.ExposicaoID); if (submeterCandidatura != null) { submeterCandidatura.Assigned = 2; submeterCandidatura.InformacaoExtra = null; db.Entry(submeterCandidatura).State = EntityState.Modified; db.SaveChanges(); } else { userAccountExposicao.Assigned = 2; db.UserAccountExposicao.Add(userAccountExposicao); db.SaveChanges(); } }
public ActionResult UploadFile() { //open file if (Request.Files.Count == 1) { //get file var postedFile = Request.Files[0]; if (postedFile.ContentLength > 0) { //read data from input stream using (var csvReader = new System.IO.StreamReader(postedFile.InputStream)) { string inputLine = ""; // Skip the firts line csvReader.ReadLine(); //read each line while ((inputLine = csvReader.ReadLine()) != null) { //get lines values string[] values = inputLine.Split(new char[] { ',', '\t' }); Candidates candidate = new Candidates { FirstName = values[0], LastName = values[1], UserName = values[2], Email = values[3], Password = values[4], ProjectId = values[5] }; if (ModelState.IsValid) { using (OurDBContext db = new OurDBContext()) { db.candidateAccount.Add(candidate); db.SaveChanges(); } //send a registration email once changes are saved in the database CustomEmail regMail = new CustomEmail(); regMail.sendMail(candidate.Email, "Select International Registration", "Welcome to our platform!"); ModelState.Clear(); ViewBag.Message = candidate.FirstName + "" + candidate.LastName + "registartion done"; } } csvReader.Close(); } } } return(Redirect("/Home/Participant")); }
//método que remove ou adiciona temas a uma exposição ou a um utilizador. ITabelas pode ser um utilizador ou uma exposição public void UpdateTemas(string[] selectedTemas, ITabelas tabela, OurDBContext dbContext) { var userAccountTemas = new HashSet <int>(tabela.Temas.Select(t => t.TemaID)); if (selectedTemas == null) { if (tabela.Temas.Count != 0) { foreach (var tema in dbContext.Tema) { if (tabela.Temas.Contains(tema)) { tabela.Temas.Remove(tema); } } } dbContext.Entry(tabela).State = EntityState.Modified; dbContext.SaveChanges(); return; } var selectedTemasHs = new HashSet <string>(selectedTemas); foreach (var tema in dbContext.Tema) { if (selectedTemasHs.Contains(tema.TemaID.ToString())) { if (!userAccountTemas.Contains(tema.TemaID)) { tabela.Temas.Add(tema); } } else { if (userAccountTemas.Contains(tema.TemaID)) { tabela.Temas.Remove(tema); } } } dbContext.Entry(tabela).State = EntityState.Modified; dbContext.SaveChanges(); }
public ActionResult Create(TipoUtilizador tipoUtilizador) { try { if (!db.TipoUtilizador.Any(n => n.Tipo == tipoUtilizador.Tipo)) { db.TipoUtilizador.Add(tipoUtilizador); db.SaveChanges(); } ModelState.Clear(); return(RedirectToAction("Index")); } catch { return(View()); } }
public IActionResult Register(UserAccount user) { if (ModelState.IsValid) { _context.UserAccount.Add(user); _context.SaveChanges(); ModelState.Clear(); ViewBag.Message = user.firstName + " " + user.LastName + " Is successfully registered"; } return(View()); }
//adiciona na bd o novo utilizador public override void SalvarBd(OurDBContext db) { MuseuInteractDb museuDB = new MuseuInteractDb(); var encrypt = museuDB.Encrypt(userAccount.Password); userAccount.Password = encrypt; encrypt = museuDB.Encrypt(userAccount.ConfirmPassword); userAccount.ConfirmPassword = encrypt; db.UserAccount.Add(userAccount); db.SaveChanges(); }
public ActionResult Edit(int UserAccountID, string nome, string morada, int numTelefone) { int id = UserAccountID; //Convert.ToInt32(Session["UserAccountID"]); var userAccountToUpdate = db.UserAccount.Include(u => u.Temas).SingleOrDefault(u => u.UserAccountID == id); if (TryUpdateModel(museuDB.EditUser(userAccountToUpdate, nome, morada, numTelefone), "", new string[] { "Nome,Morada,Idade,Sexo,NumTelefone,Email,Password,ConfirmPassword,TipoUtilizadorID" })) { try { db.Entry(museuDB.EditUser(userAccountToUpdate, nome, morada, numTelefone)).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("PerfilUser")); } catch (RetryLimitExceededException /* dex */) { ModelState.AddModelError("", "Nao foi possivel atualizar o user"); } } return(View(museuDB.EditUser(userAccountToUpdate, nome, morada, numTelefone))); }
public UserAccount Register([FromBody] UserAccount account) { if (ModelState.IsValid) { using (OurDBContext db = new OurDBContext()) { db.userAccount.Add(account); db.SaveChanges(); } ModelState.Clear(); } return(account); }
public ActionResult Create(Client client) { if (ModelState.IsValid) { using (OurDBContext db = new OurDBContext()) { db.clientAccount.Add(client); db.SaveChanges(); } ModelState.Clear(); ViewBag.Message = client.CustomerNumber + "client creation is done"; } return(View()); }
public ActionResult Create(Assessments assessment) { if (ModelState.IsValid) { using (OurDBContext db = new OurDBContext()) { db.assessmentList.Add(assessment); db.SaveChanges(); } ModelState.Clear(); ViewBag.Message = assessment.Name + "Assessment creation is done"; } return(View()); }
public ActionResult Create(Projects project) { if (ModelState.IsValid) { using (OurDBContext db = new OurDBContext()) { db.projectList.Add(project); db.SaveChanges(); } ModelState.Clear(); ViewBag.Message = project.ProjectName + "Project creation is done"; } return(View()); }
public ActionResult Register(UserAccount account) { if (ModelState.IsValid) { using (OurDBContext db = new OurDBContext()) { db.userAccount.Add(account); db.SaveChanges(); } ModelState.Clear(); ViewBag.Message = account.FirstName + " " + account.LastName + " successfully registered."; } return(View()); }
public ActionResult ExtraInfo(string UserID, int ExposicaoID, string InformacaoExtra) { int uID = Int32.Parse(UserID); UserAccountExposicao userAccountExposicaoToUpdate = db.UserAccountExposicao.Find(uID, ExposicaoID); if (userAccountExposicaoToUpdate != null) { userAccountExposicaoToUpdate.InformacaoExtra = InformacaoExtra; db.Entry(userAccountExposicaoToUpdate).State = EntityState.Modified; db.SaveChanges(); } return(RedirectToAction("Candidatura", "UserAccountExposicao")); }
public ActionResult KayitOl(UserAccount user) { if (ModelState.IsValid) { using (OurDBContext db = new OurDBContext()) { db.kullaniciHesap.Add(user); db.SaveChanges(); } ModelState.Clear(); ViewBag.Message = user.Name + "Eklenmesi Başarılı"; } return(View()); }
public async Task <IActionResult> SignUp([Bind("Email,Password,ConfirmPassword")] registered_staff staff) { try { if (ModelState.IsValid) { if (_context.registered_staff.Any(info => info.Email == staff.Email)) { ModelState.AddModelError("Email", "The email address you entered is already in use"); ViewData["Message"] = "Already a member? Log In"; return(View(staff)); } else { _context.Add(staff); await _context.SaveChanges <registered_staff>(); //var type = new staff_type(staff.StaffID); _context.staff_type.Add(new staff_type(staff.StaffID)); await _context.SaveChanges <staff_type>(); return(View("RequiredInfo")); } } else { ViewData["Message"] = "Already a member? Log In"; return(View(staff)); } } catch (Exception e) { return(Error()); } }
public ActionResult Register(Members member) { if (ModelState.IsValid) { using (OurDBContext db = new OurDBContext()) { db.memberAccount.Add(member); db.SaveChanges(); } ModelState.Clear(); ViewBag.Message = member.FirstName + " " + member.LastName + "'s Account has been created successfully"; return(RedirectToAction("Login")); } return(View()); }
public ActionResult Delete(int?id) { var temaToDelete = db.Tema.SingleOrDefault(t => t.TemaID == id); if (temaToDelete != null) { db.Tema.Remove(temaToDelete); db.SaveChanges(); TempData["Message"] = temaToDelete.Nome + " removido com sucesso"; } else { TempData["Message"] = "erro ao remover o tema"; } return(RedirectToAction("Index")); }
public ActionResult Delete(int?id) { var exposicaoToDelete = db.Exposicao.SingleOrDefault(e => e.ExposicaoID == id); if (exposicaoToDelete != null) { db.Exposicao.Remove(exposicaoToDelete); db.SaveChanges(); TempData["Message"] = exposicaoToDelete.Nome + " removido com sucesso"; } else { TempData["Message"] = "Erro ao remover Exposição"; } return(RedirectToAction("Index")); }
public ActionResult Register(UserBMI bmi) { if (ModelState.IsValid) { // Process the BMI for its type bmi.BMItype = Check_BMI(bmi.Height, bmi.Weight); using (OurDBContext db = new OurDBContext()) { db.userBMI.Add(bmi); db.SaveChanges(); } ModelState.Clear(); ViewBag.message = @"Records Archived."; } return(View()); }
public UserAccount Login([FromBody] LoginParameters loginParameters) { using (OurDBContext db = new OurDBContext()) { var usr = db.userAccount.Single(u => u.Username == loginParameters.username && u.Password == loginParameters.password); if (usr != null) { if (db.session.ToList().Count == 0) { db.session.Add(new Session()); db.SaveChanges(); } db.session.ToList()[0].UserID = usr.UserID; db.session.ToList()[0].Username = usr.Username; return(usr); } else { ModelState.AddModelError("", "Username ot Password is wrong."); } return(null); } }
public async Task <IActionResult> RequiredInfo([Bind("FirstName,MiddleInitial,LastName,Address,City,ZipCode,State,Phone,DateOfBirth,Gender, Image")] StaffRequiredInfo info) { if (info.Phone != null && info.Phone.Length < 10) { ModelState.AddModelError("Phone", "Invalid phone number."); } var validImageTypes = new string[] { "image/pjpeg", "image/jpeg", "image/tiff", "image/gif", "image/png", }; if (info.Image == null || info.Image.Length == 0) { return(View(info)); } if (!validImageTypes.Contains(info.Image.ContentType)) { ModelState.AddModelError("Image", "Please choose either a JPG, TIF, GIF or PNG image."); } if (info.DateOfBirth == null) { return(View(info)); } else { DateTime dt = Convert.ToDateTime(info.DateOfBirth); if (dt > DateTime.Today) { ModelState.AddModelError("DateOfBirth", "Date of birth must be before today's date "); } } if (ModelState.IsValid) { if (_context.registered_staff.Count() > 0) { try { registered_staff staff = _context.registered_staff.Last(); staff.FirstName = info.FirstName; staff.MiddleInitial = info.MiddleInitial; staff.LastName = info.LastName; staff.Address = info.Address; staff.City = info.City; staff.ZipCode = info.ZipCode; staff.State = info.State; staff.Phone = info.Phone; staff.DateOfBirth = info.DateOfBirth; staff.Gender = info.Gender; staff.ImageName = info.Image.FileName; var uploadDir = "uploads/images/" + staff.StaffID + "/"; var folderPath = Path.Combine(_hostingEnvironment.ContentRootPath, uploadDir); if (!Directory.Exists(folderPath)) { Directory.CreateDirectory(folderPath); } var imagePath = Path.Combine(_hostingEnvironment.ContentRootPath, folderPath, info.Image.FileName); using (FileStream f = new FileStream(imagePath, FileMode.Create, FileAccess.ReadWrite)) { await info.Image.CopyToAsync(f); } await _context.SaveChanges <registered_staff>(); FillStaffTypes(); return(RedirectToAction("AdditionalInfo")); } catch (Exception e) { return(Error()); } } } return(View(info)); }
//guarda na em bd.exposicao a exposicao em questão public override void SalvarBd(OurDBContext db) { db.Exposicao.Add(exposicao); db.SaveChanges(); }