예제 #1
0
        public IActionResult Post([Required][Image] IFormFile file)
        {
            var metadata = new FileMetadata
            {
                OriginalFileName = file.FileName,
                UploadDate       = DateTime.Now,
                FileType         = FileType.Image,
                OwnerId          = User.GetId()
            };

            var fileObj = new FileModel
            {
                Metadata = metadata,
                Data     = GetPreprocessedImage(file)
            };

            try
            {
                _db.StartTransaction();
                _db.FileMetadata.Create(metadata);
                _fs.Create(fileObj);
                _db.Commit();
            }
            catch
            {
                _db.Rollback();
                _fs.Delete(metadata);
                throw;
            }

            return(StatusCode((int)HttpStatusCode.Created, fileObj.Metadata.Id));
        }
예제 #2
0
        public int Create(ContractDTO model, Role initiatorRole)
        {
            if (!ValidateContractForCreate(model, initiatorRole, out string error))
            {
                throw new EBValidationException(error);
            }

            try
            {
                db.StartTransaction();

                int createdId  = db.Contracts.Create(_mapper.Map <Contract>(model));
                var fullEntity = db.Contracts.Read(createdId);

                var report = GeneratePdfReport(_mapper.Map <ContractDTO>(fullEntity));
                fileRepository.Create(report);

                fullEntity.ReportId = report.Metadata.Id;
                db.Contracts.Update(fullEntity);

                db.Commit();
                return(createdId);
            }
            catch
            {
                db.Rollback();
                throw;
            }
        }
예제 #3
0
        public ChatDTO CreateChat(ChatDTO chat)
        {
            try
            {
                _db.StartTransaction();
                var chatEntity = _mapper.Map <Chat>(chat);
                foreach (var u in chatEntity.Participants)
                {
                    u.AddedDate = DateTime.Now;
                }
                var chatId = _db.Chats.Create(chatEntity);
                _db.Commit();

                var created = GetChat(chatId);
                return(created);
            }
            catch
            {
                _db.Rollback();
                throw;
            }
        }
예제 #4
0
        public IActionResult Post(AdvertDTO advert)
        {
            FileMetadata image = null;

            if (advert.ImageId != null)
            {
                image = _db.FileMetadata.Read(advert.ImageId.Value);
                if (image == null)
                {
                    return(NotFound($"Image {image.Id} not found!"));
                }
                else if (image.Assigned)
                {
                    return(Conflict($"Image {image.Id} is already used!"));
                }
                else if (image.OwnerId != User.GetId())
                {
                    return(Conflict($"Image {image.Id} is owned by another user!"));
                }
            }

            advert.UserId = User.GetId();
            var advertEntity = _mapper.Map <Advert>(advert);

            try
            {
                _db.StartTransaction();
                var advertId = _db.Adverts.Create(advertEntity);
                _db.Adverts.CreateFavorite(new AdvertFavorite
                {
                    UserId   = User.GetId(),
                    AdvertId = advertId
                });

                if (image != null)
                {
                    image.Assigned = true;
                    _db.FileMetadata.Update(image);
                }

                _db.Commit();
            }
            catch
            {
                _db.Rollback();
                throw;
            }

            return(Created(string.Empty, advertEntity.Id));
        }
        public async Task <SyylabusForDepartmentDTo> CreateSyllabus(CreateSyllabusRequest request)
        {
            try
            {
                Check.NotNullOrEmpty(request, "request");
                var users     = _userRepository.GetTeacherConstraintWithLessons(request.DepartmentId);
                var locations = _locationRepository.GetFacultyLocations(request.FacultyId);
                foreach (var item in users)
                {
                    var userLessons = _lessonRepository.GetLessonsForTeacher(item.UserId);
                    item.Lessons = userLessons.Map <List <LessonDto> >();
                }

                var lessons         = _lessonRepository.GetDepartmentLessons(request.FacultyId, request.DepartmentId, request.PeriodType);
                var syllabusLessons = lessons.Map <List <SyllabusForLessonWithGroupListDto> >();
                int toplamDersSaati = 0;
                foreach (var sls in syllabusLessons)
                {
                    foreach (var hrp in sls.LessonGroups)
                    {
                        toplamDersSaati = toplamDersSaati + sls.WeeklyHour;
                    }
                }
                toplamDersSaati = toplamDersSaati * 2;
                var syllabus = SyllabusDomainFactory.Create(request);

                while (syllabus.WeeklyHour != toplamDersSaati)
                {
                    syllabus = SyllabusDomainFactory.Create(request);
                    syllabus.AssignToLesson(lessons, request, EducationType.IOgretim);
                    syllabus.AssignToLesson(lessons, request, EducationType.IIOgretim);

                    syllabus.UnitLessons.RemoveAll(x => x.LessonId == 0);

                    syllabus.HocaAta(users);
                    syllabus.UnitLessons.RemoveAll(x => x.LessonId > 0 && x.UserId == 0);

                    syllabus.DerslikAta(locations);
                    syllabus.UnitLessons.RemoveAll(x => x.LessonId > 0 && x.UserId > 0 && x.LocationId == 0);

                    syllabus.AddWeeklyHour(syllabus.UnitLessons.Count);
                    if (syllabus.WeeklyHour != toplamDersSaati)
                    {
                    }
                }

                var syllabusEntity = syllabus.Map <SyllabusEntity>();

                await _syllabusRepository.AddAsync(syllabusEntity);

                await _databaseUnitOfWork.SaveChangesAsync();

                var result = await GetSyllabus(syllabusEntity.SyllabusId).ConfigureAwait(false);

                return(result);
            }
            catch (Exception ex)
            {
                _databaseUnitOfWork.Rollback();
                throw;
            }
        }