public Guid UploadPRoposalFile() { if (!Request.Content.IsMimeMultipartContent()) { throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType); } var file = HttpContext.Current.Request.Files.Count > 0 ? HttpContext.Current.Request.Files[0] : null; if (file == null) { throw new HttpResponseException(HttpStatusCode.BadRequest); } byte[] fileData = null; using (var binaryReader = new BinaryReader(HttpContext.Current.Request.Files[0].InputStream)) { fileData = binaryReader.ReadBytes(HttpContext.Current.Request.Files[0].ContentLength); } var FileRep = IocConfig.Container.GetInstance <IProposalFileRepository>(); ProposalFile f = new ProposalFile() { ID = Guid.NewGuid(), File = fileData, ProposalID = null }; FileRep.Add(f, true); return(f.ID); }
public ProposalController(IProposalRepository repository, IMapper mapper, IUnitOfWork unitOfWork, IOptionsSnapshot <ProposalFile> snapshot, IHostingEnvironment hosting, ISemesterRepsitory semesterRepsitory, IUserRepository userRepository, ICourseRepository courseRepository) : base(repository, mapper, unitOfWork) { _hosting = hosting; _semesterRepsitory = semesterRepsitory; _userRepository = userRepository; _courseRepository = courseRepository; _file = snapshot.Value; }
public bool SubmitProposal(ProposalGeneralInfoJSON ProposalJSON, string Username) { using (var dbContextTransaction = Context.Database.BeginTransaction()) { try { bool result = true; Student s = StudentRepository.Value.SelectBy(q => q.SocialSecurityNumber == Username).FirstOrDefault(); if (s == null) { return(false); } Proposal p = new Proposal(); p.ID = Guid.NewGuid(); p.CreateDate = DateTime.Now; p.IsFinalApprove = false; p.LatestOperation = "ثبت شده توسط دانشجو"; p.LatinName = ProposalJSON.LatinName; p.Name = ProposalJSON.Name; p.ResearchTypeID = ProposalJSON.ReseachTypeID; p.ProposalStageID = StageRepository.SelectBy(w => w.Order == 1).FirstOrDefault().ID; p.ProposalStatusID = StatusRepository.SelectBy(e => e.IsDefault).FirstOrDefault().ID; p.StudentID = s.ID; p.FirstJudgeApproved = false; p.SecondJudgeApproved = false; Add(p); result &= KeywordRepository.AddProposalKeyword(ProposalJSON.keywords, p.ID); //WorkFlow ProposalWorkflowHistory work = new ProposalWorkflowHistory { ID = Guid.NewGuid(), OccuranceDate = DateTime.Now, OccuredByProfessorID = null, OccuredByStudentID = s.ID, ProposalID = p.ID, ProposalOperationID = Guid.Parse("4aaaa946-53ce-45c8-a317-20eba03867e0") }; ProposalWorkflowHistoryRepository.Add(work); // ProposalFile pf = ProposalFileRepository.Get(ProposalJSON.FileID); if (pf == null) { return(false); } else { pf.ProposalID = p.ID; } Commit(); dbContextTransaction.Commit(); dbContextTransaction.Dispose(); return(result); } catch (Exception e) { dbContextTransaction.Rollback(); dbContextTransaction.Dispose(); return(false); } } }