public ActionResult Register(Person person, HttpPostedFileBase upImage) { var user = (User)System.Web.HttpContext.Current.Session["person"]; System.Web.HttpContext.Current.Session["person"] = null; Person newPerson = new Person(user, person) { PhotoUrl = ImageHandler.HttpPostedFileBaseToByteArray(upImage), PhotoType = upImage.ContentType }; if (ModelState.IsValid == false) { return(View(newPerson)); } var returnedPerson = PersonDAO.Insert(newPerson); if (returnedPerson == null) { return(View(newPerson)); } UserSession.ReturnPubId(returnedPerson.Id); return(View(returnedPerson)); }
private static void InsertPerson() { try { UI.WriteLine("** Inserção de pessoa **"); Person person = new Person(); UI.Write(" - Nome: "); person.Name = UI.ReadLine(); UI.Write(" - Gênero (0 = M, 1 = F, 2 = Indefinido): "); person.Gender = (Gender)Convert.ToInt32(UI.ReadLine()); UI.Write(" - CPF: "); person.DocumentNumber = UI.ReadLine(); UI.Write(" - RG: "); person.Identification = UI.ReadLine(); UI.Write(" - Data de nascimento: "); person.BirthDate = Convert.ToDateTime(UI.ReadLine()); UI.Write(" - Estado civil (0 = Solt., 1 = Cas., 2 = Divorc., 3 = Viuv.): "); person.MaritalStatus = (MaritalStatus)Convert.ToInt32(UI.ReadLine()); UI.Write(" - Endereço: "); person.Address = UI.ReadLine(); UI.Write(" - Telefone: "); person.Phone = UI.ReadLine(); PersonDAO personDAO = new PersonDAO(); personDAO.Insert(person); UI.WriteLine(" *** Pessoa cadastrada com sucesso! ***"); } catch (Exception ex) { UI.WriteLine($"Houve um erro ao salvar a pessoa: {ex.Message}"); } }
public static QueryResult <Person> Insert(Person person) { var response = new QueryResult <Person>(); try { response.Data = PersonDAO.Insert(person); } catch (Exception ex) { HandleError(response, ex); } return(response); }
public ActionResult Register(Person newPerson, HttpPostedFileBase upImage) { // Verify the if the model is valid if (ModelState.IsValid == false) { ModelState.AddModelError("", "Error - Check information and try again"); return View(newPerson); } // Get the user from the session that the User Controller generated with the basic data from the user var newUser = (User)System.Web.HttpContext.Current.Session["user"]; // If there is nothing in the user session, return to the user registration page if (newUser == null) return RedirectToAction("Register", "User"); // Get the coordinates of the bar location that the user has given Tuple<double, double> tuple = GoogleGeoLocation.GetCoordinates(newPerson.Address, newPerson.City, newPerson.State); newPerson.Lat = tuple.Item1; newPerson.Lng = tuple.Item2; newPerson.Photo = ImageHandler.HttpPostedFileBaseToByteArray(upImage); newPerson.PhotoType = upImage.ContentType; newUser.RegistrationDate = DateTime.Now; newUser.UserType = nameof(Person); newUser.Password = CryptSharp.Crypter.MD5.Crypt(newUser.Password); // Insert in the database, if successful var returnedUser = UserDAO.Insert(newUser); newPerson.UserId = returnedUser.Id; var returnedPerson = PersonDAO.Insert(newPerson); if (returnedPerson == null || returnedUser == null) { ModelState.AddModelError("", "Error - Check information and try again"); return View(newPerson); } // Generate a session with the user database id UserSession.ReturnPersonId(returnedPerson.Id); UserSession.ReturnUserId(returnedPerson.UserId); System.Web.HttpContext.Current.Session["user"] = null; return RedirectToAction("Dashboard", "Person"); }