public HttpResponseMessage Post(StudentModel studentModel)
        {
            Student student = ModelsBridge.SerilizeStudent(studentModel);
            using (this.unitOfWork = new UnitOfWorkScope(true))
            {

                UnitOfWorkScope.StudentRepository.Add(student);
            }

            return this.Request.CreateResponse(HttpStatusCode.OK, student);
        }
Example #2
0
        public UnitOfWorkScope(bool toSaveAllChanges)
        {
            if ((currScope != null) && (!currScope.isDisposed))
            {
                throw new InvalidOperationException(String.Format("Nestig of contexts is not allowed!"));
            }

            this.toSaveAllChanges = toSaveAllChanges;
            this.context = new SchoolDbContext();
            this.isDisposed = false;
            Thread.BeginThreadAffinity();
            currScope = this;
        }
Example #3
0
        public void Dispose()
        {
            if (!this.isDisposed)
            {
                currScope = null;

                Thread.EndThreadAffinity();

                if (this.ToSaveAllChanges)
                {
                    this.context.SaveChanges();
                }
                this.context.Dispose();
                this.isDisposed = true;
            }
        }
        public HttpResponseMessage GetAll()
        {
            ICollection<Student> all = null;
            ICollection<StudentModel> models = null;
            using (this.unitOfWork = new UnitOfWorkScope(true))
            {
                all = UnitOfWorkScope.StudentRepository.GetAll().ToList();
            }

            models = new HashSet<StudentModel>();

            foreach (var student in all)
            {
                models.Add(ModelsBridge.SerilizeStudentModel(student));
            }

            return this.Request.CreateResponse(HttpStatusCode.OK, models);

        }