Beispiel #1
0
        static void Test8()
        {
            Mapper.CreateMap <SchoolDTO, School>()
            .ForMember(s => s.ServerPrivateKey, m => m.MapFrom(d => Convert.FromBase64String(d.ServerPrivateKey)));

            var list = new List <SchoolDTO>();

            for (int i = 0; i < 1000000; i++)
            {
                var dto = new SchoolDTO();
                dto.ID = "1";
                dto.ServerPrivateKey = Convert.ToBase64String(Encoding.UTF8.GetBytes("aa"));
                list.Add(dto);
            }

            Stopwatch watch = Stopwatch.StartNew();
            var       dfff  = Mapper.Map <IEnumerable <SchoolDTO>, IEnumerable <School> >(list);

            watch.Stop();
            string s2 = string.Empty;



            //var builder = new ContainerBuilder();
            //builder.Register((c, p) => new B(p.Named<string>("b"))).As<IB>();
            //builder.Register((c, p) => new A(c.Resolve<IB>()));
        }
        public School(SchoolDTO dto)
        {
            Name   = dto.Name;
            Email  = dto.Email;
            TelNum = dto.TelNum;

            AdresId = dto.AdresId;
        }
 public IActionResult UpdateSchool([FromBody] SchoolDTO schoolDTO)
 {
     try
     {
         var newSchool = _schoolService.UpdateSchool(schoolDTO);
         return(CreatedAtAction(nameof(UpdateSchool), schoolDTO));
     }
     catch (Exception ex)
     {
         return(BadRequest(ex.ToString()));
     }
 }
        public async Task <IHttpActionResult> GetSchool(int id)
        {
            SchoolDTO dto = await SchoolService.SearchSingleSchoolByIdAsync(id);

            if (dto != null)
            {
                return(Ok(dto));
            }
            else
            {
                return(NotFound());
            }
        }
Beispiel #5
0
        public void UpdateSchool(School school, SchoolDTO schoolDTO)
        {
            Domain.Principal updatePrincipal = _context.Principals.FirstOrDefault(s => s.Id == school.Principal.Id);
            updatePrincipal.Name      = schoolDTO.Principal.Name;
            updatePrincipal.Photo     = schoolDTO.Principal.Photo;
            updatePrincipal.BirthDate = schoolDTO.Principal.BirthDate;
            _context.SaveChanges();

            Domain.School updateSchool = _context.Schools.FirstOrDefault(s => s.Id == school.Id);
            updateSchool.Name  = schoolDTO.Name;
            updateSchool.Photo = schoolDTO.Photo;
            _context.SaveChanges();
        }
        public ActionResult CapNhatThongTinTruong(SchoolDTO schoolDTO, int id)
        {
            School school = schoolRepository.UpdateSchoolInfomation(schoolDTO, id);

            if (school.IsDaTaoMoi == false || school.IsDaTaoMoi == null)
            {
                return(Json(new ReturnFormat(400, "success", school.MaTruong)));
            }
            if (school.IsDaTaoMoi == true)
            {
                return(Json(new ReturnFormat(200, "true", school.MaTruong)));
            }
            return(Json(new ReturnFormat(200, "false", school.MaTruong)));
        }
Beispiel #7
0
        public async Task <int> AddSchool(SchoolDTO school)
        {
            if (school == null)
            {
                throw new ArgumentNullException($"School cannot be null");
            }

            var newSchool = mapper.Map <School>(school);
            await _ctx.Schools.AddAsync(newSchool);

            await _ctx.SaveChangesAsync();

            return(newSchool.SchoolId);
        }
Beispiel #8
0
        public IActionResult UpdateSchool(int schoolId, [FromBody] SchoolDTO schoolDTO)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            School school = _schoolRepository.GetSchool(schoolId);

            if (school == null)
            {
                return(NotFound());
            }
            _schoolRepository.UpdateSchool(school, schoolDTO);
            return(NoContent());
        }
Beispiel #9
0
        public async Task <SchoolDTO> UpdateSchool(SchoolDTO schoolSrc)
        {
            var entityDest = await _ctx.Schools.FindAsync(schoolSrc.SchoolId);

            if (entityDest != null)
            {
                mapper.Map(schoolSrc, entityDest);
            }
            else
            {
                return(null);
            }
            await _ctx.SaveChangesAsync();

            return(await Task.FromResult(schoolSrc));
        }
Beispiel #10
0
        public IHttpActionResult CreateSchool(SchoolDTO schoolDTO)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var school = Mapper.Map <SchoolDTO, School>(schoolDTO);

            _context.Schools.Add(school);
            _context.SaveChanges();

            schoolDTO.id = school.id;

            return(Created(new Uri(Request.RequestUri + "/" + school.id), schoolDTO));
        }
        public async Task <IHttpActionResult> UpdateSchool([FromBody] SchoolDTO SchoolModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var updatedSchool = await SchoolService.UpdateSchoolAsync(SchoolModel);

            if (updatedSchool != null)
            {
                return(Ok(updatedSchool));
            }
            else
            {
                return(NotFound());
            }
        }
        public async Task <IHttpActionResult> AddSchool([FromBody] SchoolDTO SchoolModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var newSchoolId = await SchoolService.AddSchoolAsync(SchoolModel);

            if (newSchoolId != 0)
            {
                return(Ok(newSchoolId));
            }
            else
            {
                return(NotFound());
            }
        }
        public SchoolDTO UpdateSchool(SchoolDTO schoolDTO)
        {
            var newSchool = new School()
            {
                Id   = schoolDTO.Id,
                Name = schoolDTO.Name
            };

            var result = _schoolRepository.UpdateSchool(newSchool);

            var newSchoolDTO = new SchoolDTO()
            {
                Id   = result.Id,
                Name = result.Name
            };

            return(newSchoolDTO);
        }
Beispiel #14
0
        //Update School (async)
        public async Task <SchoolDTO> UpdateSchoolAsync(SchoolDTO modelDTO)
        {
            try
            {
                using (var unitOfWork = unitOfWorkFactory.Create())
                {
                    if (!string.IsNullOrEmpty(modelDTO._ImageFileUrl))
                    {
                        var tempImageTypeModel = unitOfWork.ImageFileTypeRepository.GetSingleOrDefaultImageFileType(x => x.Type.Contains("SchoolImage"));

                        ImageFileTypeDTO imageFileTypeDTO = _Mapper_ToDTO.Map <ImageFileTypeModel, ImageFileTypeDTO>(tempImageTypeModel);

                        modelDTO.ImageFileUrl = new ImageFileUrlDTO()
                        {
                            Url             = modelDTO._ImageFileUrl,
                            CreateDate      = DateTime.Now,
                            ImageFileTypeId = imageFileTypeDTO.ImageFileTypeId
                        };
                    }
                    else
                    {
                        modelDTO.ImageFileUrl = null;
                    }

                    SchoolModel model = _Mapper_ToModel.Map <SchoolDTO, SchoolModel>(modelDTO);

                    bool result = unitOfWork.SchoolRepository.Update(model);

                    SchoolDTO modelRTN = null;
                    if (result)
                    {
                        await unitOfWork.SaveChangesAsync();

                        modelRTN = _Mapper_ToDTO.Map <SchoolModel, SchoolDTO>(model);
                    }
                    return(modelRTN);
                }
            }
            catch (Exception ex)
            {
                LogException(ex);
                throw ex;
            }
        }
Beispiel #15
0
        public IHttpActionResult UpdateSchool(int id, SchoolDTO schoolDTO)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var school = _context.Schools.SingleOrDefault(c => c.id == id);

            if (school == null)
            {
                NotFound();
            }

            Mapper.Map(schoolDTO, school);
            _context.SaveChanges();

            return(Ok());
        }
        public IHttpActionResult PostSchoolData([FromBody] JObject data)
        {
            SchoolDTO schoolDTO = data["schoolDTO"].ToObject <SchoolDTO>();
            IEnumerable <DepartmentDTO> departmentDTOs = data["departmentDTO"].ToObject <IEnumerable <DepartmentDTO> >();
            IEnumerable <CourseDTO>     courseDTOs     = data["CourseDTO"].ToObject <IEnumerable <CourseDTO> >();
            IEnumerable <TeacherDTO>    teacherDTOs    = data["TeacherDTO"].ToObject <IEnumerable <TeacherDTO> >();
            SchoolRegistrationManager   srm            = new SchoolRegistrationManager();

            try
            {
                srm.SchoolRegister(schoolDTO, departmentDTOs, courseDTOs, teacherDTOs);
                return(Ok());
            }

            catch (SchoolRegistrationException ex)
            {
                return(Content(HttpStatusCode.Conflict, "School with same name exists"));
            }
        }
Beispiel #17
0
        public IActionResult UpdateSchool(int schoolId, [FromBody] SchoolDTO schoolDTO)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            School school = _schoolRepository.GetSchool(schoolId);

            if (school == null)
            {
                return(NotFound());
            }
            school.Name           = schoolDTO.Name;
            school.Principal      = schoolDTO.Principal;
            school.MentorsList    = schoolDTO.MentorsList;
            school.StudentsList   = schoolDTO.StudentsList;
            school.CoursesList    = schoolDTO.CoursesList;
            school.CataloguesList = schoolDTO.CataloguesList;
            return(NoContent());
        }
Beispiel #18
0
        public IActionResult CreateSchool([FromBody] SchoolDTO schoolDTO)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            int    maxSchoolId = _schoolRepository.GetAllSchools().Max(s => s.Id);
            School school      = new School()
            {
                Id             = ++maxSchoolId,
                Name           = schoolDTO.Name,
                Principal      = schoolDTO.Principal,
                MentorsList    = schoolDTO.MentorsList,
                StudentsList   = schoolDTO.StudentsList,
                CoursesList    = schoolDTO.CoursesList,
                CataloguesList = schoolDTO.CataloguesList
            };

            _schoolRepository.AddSchool(school);
            return(CreatedAtRoute("GetSchool", new { schoolId = school.Id }, school));
        }
        public School UpdateSchoolInfomation(SchoolDTO schoolDTO, int id)
        {
            School school = GetSchoolById(id);

            school.WardId           = schoolDTO.WardId;
            school.SoNhaTenDuong    = schoolDTO.SoNhaTenDuong;
            school.Email            = schoolDTO.Email;
            school.SDT              = schoolDTO.SDT;
            school.MaSoThue         = schoolDTO.MaSoThue;
            school.HieuTruong       = schoolDTO.HieuTruong;
            _db.Entry(school).State = EntityState.Modified;
            try
            {
                _db.SaveChanges();
            }
            catch (Exception)
            {
                return(null);
            }
            return(school);
        }
Beispiel #20
0
        public IActionResult CreateSchool([FromBody] SchoolDTO schoolDTO)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            School school = new School()
            {
                Name       = schoolDTO.Name,
                Principal  = schoolDTO.Principal,
                Photo      = schoolDTO.Photo,
                Mentors    = schoolDTO.Mentors,
                Students   = schoolDTO.Students,
                Courses    = schoolDTO.Courses,
                Catalogues = schoolDTO.Catalogues,
                Subjects   = schoolDTO.Subjects
            };

            _schoolRepository.AddSchool(school);
            return(CreatedAtRoute("GetSchool", new { schoolId = school.Id }, school));
        }
        public IHttpActionResult GetSchool(int id)
        {
            var ss = _db.schools_tb.FirstOrDefault((s) => s.school_id == id);

            SchoolDTO school = new SchoolDTO();

            school.school_id     = ss.school_id;
            school.school_name   = ss.school_name;
            school.city_name     = ss.city_name;
            school.province_name = ss.province_name;

            school.country_name = ss.country_name;
            school.address      = ss.address;

            school.phone        = ss.phone;
            school.date_created = ss.date_created;


            if (school == null)
            {
                return(NotFound());
            }
            return(Json(school));
        }
Beispiel #22
0
 public async Task <SchoolDTO> UpdateSchool(SchoolDTO school)
 {
     return(await _schoolService.UpdateSchool(school));
 }
Beispiel #23
0
        public void Add(SchoolDTO school)
        {
            var addedSchool = _dbContext.Schools.Add(new Entities.School(school.Name, school.NIP, school.Street, school.Number, school.PostalCode, school.City, school.Email, school.Telephone, school.Director));

            _dbContext.SaveChanges();
        }
Beispiel #24
0
 public IHttpActionResult GetStudents(SchoolDTO dto)
 {
     return(Ok());
 }
Beispiel #25
0
		public async Task<IHttpActionResult> ModifySchool(SchoolDTO model)
		{
			if (ModelState.IsValid)
			{
				try
				{
					await _schoolService.Save(model);
					return this.Ok();
				}
				catch (Exception ex)
				{
					return this.BadRequest(ex.Message);
				}
			}
			else
			{
				return this.BadRequest(ModelState);
			}
		}
Beispiel #26
0
 public async Task <int> AddSchool(SchoolDTO school)
 {
     return(await _schoolRepository.AddSchool(school));
 }
Beispiel #27
0
 public async Task <SchoolDTO> UpdateSchool(SchoolDTO school)
 {
     return(await _schoolRepository.UpdateSchool(school));
 }
Beispiel #28
0
        public void SchoolRegister(SchoolDTO schoolDto, IEnumerable <DepartmentDTO> departmentDTOs, IEnumerable <CourseDTO> courseDTOs, IEnumerable <TeacherDTO> teacherDTOs)
        {
            using (DatabaseContext context = new DatabaseContext())
            {
                using (DbContextTransaction transaction = context.Database.BeginTransaction())
                {
                    try
                    {
                        schoolRegServ = new SchoolRegistrationService(context);
                        var foundSchool = schoolRegServ.FindSchool(schoolDto.SchoolName);
                        if (foundSchool != null)
                        {
                            throw new SchoolRegistrationException();
                        }
                        if (foundSchool == null)
                        {
                            var newSchool = new School
                            {
                                Name         = schoolDto.SchoolName,
                                ContactEmail = schoolDto.SchoolContactEmail,
                                EmailDomain  = schoolDto.SchoolEmailDomain
                            };
                            foundSchool = schoolRegServ.CreateSchool(newSchool);
                            context.SaveChanges();
                        }

                        foreach (DepartmentDTO d in departmentDTOs)
                        {
                            var foundDepartment = schoolRegServ.FindDepartment(d.DepartmentName);
                            if (foundDepartment == null)
                            {
                                var newDepartment = new Department
                                {
                                    Name = d.DepartmentName
                                };
                                foundDepartment = schoolRegServ.CreateDepartment(newDepartment);
                                context.SaveChanges();
                            }

                            var foundSchoolDepartment = schoolRegServ.FindSchoolDepartment(foundSchool.Name, foundDepartment.Name);
                            if (foundSchoolDepartment == null)
                            {
                                var newSchoolDepartment = new SchoolDepartment
                                {
                                    School     = foundSchool,
                                    Department = foundDepartment,
                                };
                                foundSchoolDepartment = schoolRegServ.CreateSchoolDepartment(newSchoolDepartment);
                                context.SaveChanges();
                            }

                            foreach (TeacherDTO t in teacherDTOs)
                            {
                                var foundTeacher = schoolRegServ.FindTeacher(t.FirstName, t.LastName);

                                if (t.DepartmentName.Equals(foundDepartment.Name))
                                {
                                    if (foundTeacher == null)
                                    {
                                        var newTeacher = new Teacher(t.FirstName, t.LastName);

                                        foundTeacher = schoolRegServ.CreateTeacher(newTeacher);
                                        context.SaveChanges();
                                    }

                                    SchoolTeacher foundSchoolTeacher = schoolRegServ.FindSchoolTeacher(foundSchool.Name, foundDepartment.Name, foundTeacher.FirstName, foundTeacher.LastName);
                                    if (foundSchoolTeacher == null)
                                    {
                                        var newSchoolTeacher = new SchoolTeacher
                                        {
                                            Teacher          = foundTeacher,
                                            SchoolDepartment = foundSchoolDepartment
                                        };
                                        foundSchoolTeacher = schoolRegServ.CreateSchoolTeacher(newSchoolTeacher);
                                        context.SaveChanges();
                                    }

                                    foreach (CourseDTO c in courseDTOs)
                                    {
                                        if (c.DepartmentName.Equals(foundDepartment.Name) &&
                                            c.TeacherFirstName.Equals(foundTeacher.FirstName) &&
                                            c.TeacherLastName.Equals(foundTeacher.LastName))
                                        {
                                            var foundCourse = schoolRegServ.FindCourse(c.CourseName);
                                            if (foundCourse == null)
                                            {
                                                var newCourse = new Course
                                                {
                                                    Name             = c.CourseName,
                                                    SchoolDepartment = foundSchoolDepartment
                                                };
                                                foundCourse = schoolRegServ.CreateCourse(newCourse);
                                                context.SaveChanges();
                                            }
                                            SchoolTeacherCourse foundSchoolTeacherCourse = schoolRegServ.FindSchoolTeacherCourse(foundSchool.Name, foundDepartment.Name, foundTeacher.FirstName, foundTeacher.LastName, foundCourse.Name);
                                            if (foundSchoolTeacherCourse == null)
                                            {
                                                var newSchoolTeacherCourse = new SchoolTeacherCourse
                                                {
                                                    SchoolTeacher = foundSchoolTeacher,
                                                    Course        = foundCourse
                                                };
                                                schoolRegServ.CreateSchoolTeacherCourse(newSchoolTeacherCourse);
                                                context.SaveChanges();
                                            }
                                        }
                                    }
                                }
                            }
                        }


                        transaction.Commit();
                    }
                    catch (SchoolRegistrationException schoolEX)
                    {
                        throw schoolEX;
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();
                    }
                }
            }
        }
Beispiel #29
0
 /// <summary>
 /// Initialise une nouvelle instance de School à partir d'un DTO existant.
 /// </summary>
 /// <param name="dto">Un dto.</param>
 public School(SchoolDTO dto)
 {
     Data = dto;
 }
Beispiel #30
0
 /// <summary>
 /// Initialise une nouvelle instance de School
 /// </summary>
 public School()
 {
     Data = new SchoolDTO();
 }
Beispiel #31
0
 public async Task <int> AddSchool([FromBody] SchoolDTO school)
 {
     return(await _schoolService.AddSchool(school));
 }