Exemple #1
0
        public async Task <IActionResult> EditEductionalCenterGroup([FromForm] EductionalCenterGroup eductionalCenterGroup, int eductionalCenterGroupId, IFormFile file)
        {
            EductionalCenterGroup editEductionalCenterGroup;

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            if (eductionalCenterGroupId != 0)
            {
                editEductionalCenterGroup = await _eductionalCenterGroupRepository.GetEductionalCenterGroupById(eductionalCenterGroupId); //GetTeacherPhoneById search

                if (editEductionalCenterGroup == null)
                {
                    return(Content("not found , please Check!..."));
                }
                else if (eductionalCenterGroup.Logo != null)
                {
                    var path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot\\EductionalCenterPictures", eductionalCenterGroup.Logo);
                    if (System.IO.File.Exists(path))
                    {
                        System.IO.File.Delete(path);
                    }
                }
            }
            if (eductionalCenterGroup == null)
            {
                return(NotFound());
            }
            if (file.Length == 0)
            {
                return(BadRequest("Empty file"));
            }
            if (file.Length > _photoSetting.MaxBytes)
            {
                return(BadRequest("Max file size exceeded"));
            }
            if (!_photoSetting.IsSupported(file.FileName))
            {
                return(BadRequest("Invalid file type"));
            }
            var uploadsFolderPath = Path.Combine(_host.WebRootPath, "GroupsPictures");

            if (!Directory.Exists(uploadsFolderPath))
            {
                Directory.CreateDirectory(uploadsFolderPath);
            }
            var fileName = Guid.NewGuid().ToString() + Path.GetExtension(file.FileName);
            var filePath = Path.Combine(uploadsFolderPath, fileName);  // filepath

            using (var stream = new FileStream(filePath, FileMode.Create))
            {
                await file.CopyToAsync(stream); // picture saved to the path (folder)
            }
            eductionalCenterGroup.Logo = fileName;
            await _eductionalCenterGroupRepository.EditEductionalCenterGroup(eductionalCenterGroup, eductionalCenterGroupId);

            return(Created("EductionalCenterTable", eductionalCenterGroup));
        }
Exemple #2
0
        public async Task <ActionResult> DeleteEductionalCenterGroup(int eductionalCenterGroupId)
        {
            if (ModelState.IsValid)   // will make check on this group have students or no
            {
                EductionalCenterGroup eductionalCenterGroup = await _eductionalCenterGroupRepository.GetEductionalCenterGroupById(eductionalCenterGroupId);

                if (eductionalCenterGroup != null)
                {
                    await _eductionalCenterGroupRepository.DeleteEductionalCenterGroup(eductionalCenterGroupId);

                    return(Ok("Deleted Successfully !!!."));
                }
                return(NotFound());
            }
            return(BadRequest());
        }
Exemple #3
0
        // Edit
        public async Task EditEductionalCenterGroup(EductionalCenterGroup newEductionalCenterGroup, int eductionalCenterGroupId)  // for editing profile
        {
            EductionalCenterGroup oldEductionalCenterGroup = await GetEductionalCenterGroupById(eductionalCenterGroupId);

            oldEductionalCenterGroup.Name           = newEductionalCenterGroup.Name;
            oldEductionalCenterGroup.TeacherId      = newEductionalCenterGroup.TeacherId;
            oldEductionalCenterGroup.SubjectId      = newEductionalCenterGroup.SubjectId;
            oldEductionalCenterGroup.GradeId        = newEductionalCenterGroup.GradeId;
            oldEductionalCenterGroup.Description    = newEductionalCenterGroup.Description;
            oldEductionalCenterGroup.TotleStudents  = newEductionalCenterGroup.TotleStudents;
            oldEductionalCenterGroup.DateFrom       = newEductionalCenterGroup.DateFrom;
            oldEductionalCenterGroup.DateTo         = newEductionalCenterGroup.DateTo;
            oldEductionalCenterGroup.PriceInMonth   = newEductionalCenterGroup.PriceInMonth;
            oldEductionalCenterGroup.Status         = newEductionalCenterGroup.Status;
            oldEductionalCenterGroup.ArchivedReason = newEductionalCenterGroup.ArchivedReason;
            //_context.Parents.Update(oldEductionalCenterGroup);
            _context.Entry(oldEductionalCenterGroup).State = EntityState.Modified;
            await _context.SaveChangesAsync();
        }
Exemple #4
0
        public async Task <ActionResult> AddEductionalCenterGroup([FromForm] EductionalCenterGroup eductionalCenterGroup, IFormFile file)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            if (eductionalCenterGroup == null)
            {
                return(NotFound());
            }
            if (file.Length == 0)
            {
                return(BadRequest("Empty file"));
            }
            if (file.Length > _photoSetting.MaxBytes)
            {
                return(BadRequest("Max file size exceeded"));
            }
            if (!_photoSetting.IsSupported(file.FileName))
            {
                return(BadRequest("Invalid file type"));
            }
            var uploadsFolderPath = Path.Combine(_host.WebRootPath, "GroupsPictures");

            if (!Directory.Exists(uploadsFolderPath))
            {
                Directory.CreateDirectory(uploadsFolderPath);
            }
            var fileName = Guid.NewGuid().ToString() + Path.GetExtension(file.FileName);
            var filePath = Path.Combine(uploadsFolderPath, fileName);  // filepath

            using (var stream = new FileStream(filePath, FileMode.Create))
            {
                await file.CopyToAsync(stream); // picture saved to the path (folder)
            }

            eductionalCenterGroup.Logo = fileName;

            await _eductionalCenterGroupRepository.AddEductionalCenterGroup(eductionalCenterGroup);

            return(Created("EductionalCenterGroupTable", eductionalCenterGroup));
        }
Exemple #5
0
        // Add EductionalCenterGroup
        public async Task AddEductionalCenterGroup(EductionalCenterGroup eductionalCenterGroup)
        {
            await _context.EductionalCenterGroups.AddAsync(eductionalCenterGroup);

            await _context.SaveChangesAsync();
        }