当前位置: 首页>>代码示例>>C#>>正文


C# HttpResponseMessage.Forbidden方法代码示例

本文整理汇总了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;
        }
开发者ID:ElectricCoffee,项目名称:Project-Late-2013-ASP-REST,代码行数:27,代码来源:ConcreteBookingController.cs

示例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;
        }
开发者ID:ElectricCoffee,项目名称:Project-Late-2013-ASP-REST,代码行数:30,代码来源:LoginController.cs

示例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;
        }
开发者ID:ElectricCoffee,项目名称:Project-Late-2013-ASP-REST,代码行数:14,代码来源:SubjectController.cs

示例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;
        }
开发者ID:ElectricCoffee,项目名称:Project-Late-2013-ASP-REST,代码行数:46,代码来源:ConcreteBookingController.cs

示例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;
        }
开发者ID:ElectricCoffee,项目名称:Project-Late-2013-ASP-REST,代码行数:89,代码来源:RegisterStudentController.cs

示例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;
        }
开发者ID:ElectricCoffee,项目名称:Project-Late-2013-ASP-REST,代码行数:19,代码来源:PossibleBookingController.cs


注:本文中的System.Net.Http.HttpResponseMessage.Forbidden方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。