本文整理汇总了C#中System.Net.Http.HttpResponseMessage.Forbidden方法的典型用法代码示例。如果您正苦于以下问题:C# HttpResponseMessage.Forbidden方法的具体用法?C# HttpResponseMessage.Forbidden怎么用?C# HttpResponseMessage.Forbidden使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.Http.HttpResponseMessage
的用法示例。
在下文中一共展示了HttpResponseMessage.Forbidden方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Delete
public HttpResponseMessage Delete([FromUri] int id)
{
var message = new HttpResponseMessage();
var bookingRepo = new Repositories.BookingRepository(_db);
var concBookingRepo = new Repositories.ConcreteBookingRepository(_db);
var concBook = concBookingRepo.GetById(id);
var book = bookingRepo.GetById(concBook.BookingId);
if (book != null)
{
//using (var transaction = new TransactionScope())
//{
bookingRepo.DeleteOnSubmit(book);
_db.SafeSubmitChanges();
if (bookingRepo.Single(b => b == book) == null)
message.OK(RESPONSE_OK);
else message.Forbidden("You done derped, son");
//}
}
else
message.Forbidden("Den valgte række i tabellen kunne ikke findes");
return message;
}
示例2: Get
public HttpResponseMessage Get([FromUri] string username, [FromUri] string password)
{
Bruger br = _db.Brugers.FirstOrDefault(b => b.Brugernavn == username && b.Password == password);
var accessLevel = default(Models.AccessLevel);
var response = new HttpResponseMessage();
if (br != null)
{
// gets the access level depending on which table the user exists in
accessLevel =
_db.Administrators.FirstOrDefault(a => a.Bruger_id == br._id) != null ? Models.AccessLevel.Administrator :
_db.Lærers.FirstOrDefault(l => l.Bruger_id == br._id) != null ? Models.AccessLevel.Teacher :
_db.Studerendes.FirstOrDefault(s => s.Bruger_id == br._id) != null ? Models.AccessLevel.Student :
Models.AccessLevel.Error;
var auth = new Models.Authentification(username, password, accessLevel);
_authRepo.Add(auth);
Debug.WriteLine(string.Format(
"User logged in with credentials \"{0}\" and \"{1}\" at {2}", auth.Username, auth.Password, DateTime.Now));
response.OK(auth.SerializeToJsonObject());
}
else
response.Forbidden("Brugernavn eller adgangskode ikke korrekt");
return response;
}
示例3: Get
public HttpResponseMessage Get([FromUri]int teacherId)
{
var subjects = _db.Subjects;
var response = new HttpResponseMessage();
var subject = subjects.FirstOrDefault(s => s.Teacher.Id == teacherId);
if (subject != null)
response.OK(subject.SerializeToJsonObject());
else
response.Forbidden("Den pågældende lærer blev ikke fundet");
return response;
}
示例4: Post
public HttpResponseMessage Post([FromBody] Models.ConcreteBooking concreteBooking)
{
// Set the number of Errors to 0
var numberOfErrors = 0;
// make new repository of the possible booking database table
var possibleBookingRepo = new Repositories.PossibleBookingRepository(_db);
// find the first possible booking that mathces the id in the concrete booking
var possibleBooking = possibleBookingRepo.Single(pb => pb.Id == concreteBooking.PossibleBookingId);
if (possibleBooking != null)
{
//Get subject from database if subject id exists
var cls = _db.Subjects.FirstOrDefault(f => f.Id == possibleBooking.Subject.Id);
if (cls != null)
{
// create a student repository based on the student database table
var studentRepo = new Repositories.StudentRepository(_db);
// correct the subject field in the object
concreteBooking.Subject = _db.GetTable<Models.Subject>().FirstOrDefault(s => s.Name.Equals(concreteBooking.Subject.Name));
// correct the student field in the object
concreteBooking.Student = studentRepo.Single(s => s.Username.Equals(concreteBooking.Student.Username));
// insert the object to the table in the database
_db.GetTable<Models.ConcreteBooking>().InsertOnSubmit(concreteBooking);
// write the changes
_db.SafeSubmitChanges(ref numberOfErrors);
}
}
else
numberOfErrors++;
//Create new HttpResponseMessage
var message = new HttpResponseMessage();
//If there are errors send forbidden else send OK
if (numberOfErrors != 0)
message.Forbidden("Errors: " + numberOfErrors);
else message.OK(RESPONSE_OK);
//Returns the HttpResponseMessage
return message;
}
示例5: Post
public HttpResponseMessage Post(
//[FromUri] string firstname, [FromUri] string lastname, [FromUri] string Username, [FromUri] string password, [FromUri] string homeroomClass)
[FromBody]Models.Student student)
{
var numberOfErrors = 0;
//var json = jsonBytes.ConvertToString();
//var student = json.DeserializeJson<Models.Student>();
Action<BookingSystemDataContext> submitChanges = db =>
{
try
{
db.SubmitChanges();
}
catch (Exception e)
{
numberOfErrors++;
Debug.WriteLine("DEBUG: " + e.Message);
}
};
var classId = 0;
var cls = _db.Holds.FirstOrDefault(h => h.Navn.Equals(student.HomeRoomClass.Name));
// checks if cls exits in table
if (cls != null)
{
// checks if it is an eal mail and if it exists in the database
if (student.Username.Contains("@edu.eal.dk") && _db.Brugers.FirstOrDefault(b => b.Brugernavn.Equals(student.Username)) == null)
{
classId = cls._id;
student.Username.Replace("@edu.eal.dk", ""); // remove the ending
submitChanges(_db);
Debug.WriteLine("Homeroom name: " + student.HomeRoomClass.Name);
Debug.WriteLine("Finished searching through holds, number of errors: " + numberOfErrors);
Navn name = new Navn
{
Fornavn = student.Name.FirstName,
Efternavn = student.Name.LastName
};
_db.Navns.InsertOnSubmit(name);
submitChanges(_db);
Debug.WriteLine("Finished adding a name, number of errors: " + numberOfErrors);
Bruger user = new Bruger
{
Navn_id = name._id,
Brugernavn = student.Username,
Password = student.Password
};
_db.Brugers.InsertOnSubmit(user);
submitChanges(_db);
Debug.WriteLine("Finished adding a user, number of errors: " + numberOfErrors);
Studerende stud = new Studerende
{
Godkendt = 0,
Bruger_id = user._id,
Hold_id = classId
};
_db.Studerendes.InsertOnSubmit(stud);
submitChanges(_db);
Debug.WriteLine("Finished adding a student, number of errors: " + numberOfErrors);
}
else numberOfErrors++;
}
else
{
numberOfErrors++;
Debug.WriteLine("DEBUG: Couldn't find the specified homeroom");
}
var message = new HttpResponseMessage();
if (numberOfErrors != 0)
message.Forbidden("Errors: " + numberOfErrors);
else message.OK("{\"Response\":\"OK\"}");
return message;
}
示例6: Post
public HttpResponseMessage Post([FromBody]Models.PossibleBooking possibleBooking)
{
var message = new HttpResponseMessage();
// gets the subject from the database
var subject = _db.GetTable<Models.Subject>().SingleOrDefault(s => s.Name == possibleBooking.Subject.Name);
if (subject != null)
{
// write it to the database
_db.GetTable<Models.PossibleBooking>().InsertOnSubmit(possibleBooking);
// commit changes to the database
_db.SafeSubmitChanges();
message.OK("{\"Response\":\"OK\"}");
}
else message.Forbidden("Faget blev ikke fundet");
return message;
}