public async Task<ActionResult> Login(LoginModel model, string returnUrl) { var response = userRepository.ValidateUser(new User(){USERNAME=model.UserName, PASSWORD=model.Password} ); //var response = new AlertasBC.Model.Utils.RepositoryResponse<User>() { Data = new User() { NAME = "Karina", ID_DEPENDENCY = "1", USERNAME = "******" }, Success=true }; if (ModelState.IsValid && response.Success) { var user = response.Data; FormsAuthentication.SetAuthCookie(user.USERNAME, false); DependencyRepository dependencyRepository = new DependencyRepository(); var getDependency = await dependencyRepository.Get(user.ID_DEPENDENCY); if (getDependency.Success) { Session["Dependency"] = getDependency.Data.NAME; Session["User"] = user; return RedirectToLocal(returnUrl); } } // If we got this far, something failed, redisplay form ModelState.AddModelError("", "El usuario o contraseña es incorrecto."); return View(model); }
public async Task<ActionResult> Register() { DependencyRepository dependencyRepository= new DependencyRepository(); var x= await dependencyRepository.GetDependencies(); ViewBag.DependencyList = new SelectList(x.Data, "ID", "NAME"); return View(); }
public async Task<RepositoryResponse<User>> RegisterUser(User user) { var response = new RepositoryResponse<User> { }; try { var userObject = new ParseUser() { Username = user.USERNAME, Password = user.PASSWORD }; userObject["Name"] = user.NAME; DependencyRepository DependencyContext = new DependencyRepository(); RepositoryResponse<ParseObject> Dependency = await DependencyContext.GetDependencyById(user.ID_DEPENDENCY); ParseQuery<ParseObject> query = new ParseQuery<ParseObject>("Dependency"); IEnumerable<ParseObject> result = await query.FindAsync(); var relation = userObject.GetRelation<ParseObject>("ID_Dependency"); relation.Add(Dependency.Data); await userObject.SignUpAsync(); response.Success = true; response.Data = userObject.ToUser(); // Register was successful. } catch (Exception ex) { response.Success = false; response.Error = ex; } return response; }
public async Task<ActionResult> Register(User model) { DependencyRepository dependencyRepository = new DependencyRepository(); if (ModelState.IsValid) { // Attempt to register the user try { var response = await userRepository.RegisterUser(model); if (response.Success) { var user = response.Data; FormsAuthentication.SetAuthCookie(user.USERNAME, false); var getDependency = await dependencyRepository.Get(user.ID_DEPENDENCY); if (getDependency.Success) { Session["Dependency"] = getDependency.Data.NAME; Session["User"] = user; return RedirectToAction("Index", "Home"); } } else { ModelState.AddModelError("", response.Error); } } catch (MembershipCreateUserException e) { ModelState.AddModelError("", ErrorCodeToString(e.StatusCode)); } } // If we got this far, something failed, redisplay form dependencyRepository = new DependencyRepository(); var x = await dependencyRepository.GetDependencies(); ViewBag.DependencyList = new SelectList(x.Data, "ID", "NAME"); return View(model); }
public async Task<RepositoryResponse<Notification>> AddNotification(Notification notification) { var response = new RepositoryResponse<Notification> { }; try { var Noti = Parse.ParseObject.Create("Notification"); #region Add Dependency Relationship DependencyRepository DependencyContext = new DependencyRepository(); RepositoryResponse<ParseObject> Dependency = await DependencyContext.GetDependencyById(notification.ID_DEPENDENCY); ParseQuery<ParseObject> query = new ParseQuery<ParseObject>("Dependency"); IEnumerable<ParseObject> result = await query.FindAsync(); #endregion #region Add City Relationship CityRepository CityContext = new CityRepository(); RepositoryResponse<ParseObject> City = await CityContext.GetCityById(notification.ID_CITY); query = new ParseQuery<ParseObject>("City"); result = await query.FindAsync(); #endregion var relation = Noti.GetRelation<ParseObject>("ID_Dependency"); relation.Add(Dependency.Data); relation = Noti.GetRelation<ParseObject>("ID_City"); relation.Add(City.Data); var message = string.Format("{0} > {1}: {2}", Dependency.Data["Name"].ToString(), City.Data["Name"].ToString(), notification.NOTIFICATION_TEXT); Noti.Add("NotificationText", message); await Noti.SaveAsync(); await Noti.SaveAsync(); var push = new ParsePush(); push.Query = from installation in ParseInstallation.Query where installation.Get<string>("City").Contains(notification.ID_CITY) select installation; push.Alert = message; await push.SendAsync(); notification.ID = Noti.ObjectId; response.Data = notification; response.Success = true; } catch (Exception ex) { response.Success = false; response.Error = ex; } return response; }