public ActionResult Add(Student student) { if (ModelState.IsValid) { _unit.StudentsRepository.Add(student); _unit.SaveChanges(); return(RedirectToAction("Index")); } return(View(student)); }
public void AddReview(ReviewDisplay rd, int restId) { try { _workUnit.Reviews.Add(dsp.ToModel(rd, restId)); _workUnit.SaveChanges(); } catch (Exception e) { logger.Error(e.Message); } }
public void AddRestaurant(RestaurantDisplay rd) { try { _workUnit.Restaurants.Add(dsp.ToModel(rd)); _workUnit.SaveChanges(); } catch (Exception e) { logger.Error(e.Message); } }
/// <summary> /// Crea una nueva instancia de Autorización HTTP OAuth 1.0a a partir de los parámetros /// de la cabecera HTTP Authorization. /// </summary> /// <param name="oAuthParametersLine"> /// Cadena después de "OAuth " de la cabecera HTTP Authorization. /// </param> /// <param name="database"> /// Contexto de Base de Datos a utilizar para identificar el Consumer y Token. /// </param> public HttpOAuthAuthorization(string oAuthParametersLine) { // --- Obtener parámetros de OAuth --- var oAuthParametersStrings = oAuthParametersLine.Trim().Split(new char[] { ',' }); foreach (string param in oAuthParametersStrings) { var paramKeyValue = param.Trim().Split(new char[] { '=' }, 2); if (paramKeyValue.Length != 2) { continue; } var match = Regex.Match(paramKeyValue[1], "\"([^\"]*)"); if (!match.Success) { continue; } oAuthParameters.Add( paramKeyValue[0].Trim(), match.Groups[1].Value ); } // --- Capturar parámetros de OAuth --- if (oAuthParameters.AllKeys.Contains("oauth_consumer_key")) { this.ConsumerKey = Database.ApiKeyStore.Get(oAuthParameters["oauth_consumer_key"]); } if (oAuthParameters.AllKeys.Contains("oauth_token")) { this.Token = Database.TokenStore.Get(oAuthParameters["oauth_token"]); } if (this.Token != null) { bool killToken = false; if (this.Token.ExpirationDate.HasValue) { killToken = this.Token.ExpirationDate.Value < DateTime.UtcNow; } if (this.Token.LoginAttempts > 5) { killToken = true; } if (killToken) { Database.TokenStore.Delete(this.Token.Guid); Database.SaveChanges(); } } try { if (oAuthParameters["oauth_signature_method"] == "HMAC-SHA1") { this.Signature = HttpUtility.UrlDecode(oAuthParameters["oauth_signature"]); } } catch (KeyNotFoundException) { } try { var oAuthTimestampString = oAuthParameters["oauth_timestamp"]; var oAuthTimestampSeconds = long.Parse(oAuthTimestampString, CultureInfo.InvariantCulture); var timestampBase = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc) .AddSeconds(oAuthTimestampSeconds); // Comparar tiempos (no debe estar más atrás ni delante de 3 minutos) var timestampSpan = DateTime.UtcNow - timestampBase; if (timestampSpan.Seconds < 181 && timestampSpan.Seconds > -179) { this.Timestamp = timestampBase; } } catch (Exception ex) { throw new HttpBadRequestException( "109 " + MessageHandlerStrings.Warning109_OAuthTimestampInvalid, ex ); } try { if (oAuthParameters["oauth_version"] == "1.0" || oAuthParameters["oauth_version"] == "1.0a") { this.Version = new Version(1, 0); } } catch (KeyNotFoundException) { } try { var oAuthNonce = oAuthParameters["oauth_nonce"]; var nonce = Database.OAuthNonceStore.GetFirst( f => f.Nonce == oAuthNonce ); if (nonce == null) { this.Nonce = new OAuthNonce { Nonce = oAuthNonce }; Database.OAuthNonceStore.Add(this.Nonce); Database.SaveChanges(); } } catch (KeyNotFoundException) { } try { if (oAuthParameters["oauth_callback"] != "oob") { this.CallbackUri = new Uri(oAuthParameters["oauth_callback"]); } } catch (KeyNotFoundException) { } catch (ArgumentNullException) { } catch (UriFormatException ex) { throw new HttpBadRequestException( "108 " + MessageHandlerStrings.Warning108_OAuthCallbackInvalid, ex ); } try { this.VerifierCode = new Guid(oAuthParameters["oauth_verifier"]); } catch (KeyNotFoundException) { } catch (ArgumentNullException) { } catch (FormatException ex) { throw new HttpBadRequestException( "107 " + MessageHandlerStrings.Warning107_OAuthVerifierInvalid, ex ); } }