Exemplo n.º 1
0
        public ActionResult Create(DocumentWebServiceReference.Document document)
        {
            try
            {
                byte[] buffer = new byte[Request.Files["file1"].ContentLength];
                Request.Files["file1"].InputStream.Read(buffer, 0, buffer.Length);
                document.Extension = Request.Files["file1"].FileName.Substring(Request.Files["file1"].FileName.LastIndexOf('.'));
                document.File      = buffer;

                using (var service = new CandidateWebServiceReference.CandidatesService())
                {
                    document.CandidateId = service.GetCandidateByLogin(this.GetLogin()).Id;
                }

                using (var service = new DocumentWebServiceReference.DocumentsService())
                {
                    int  ID;
                    bool result;
                    service.SaveDocument(document, document.CandidateId, true, document.Type, true, out ID, out result);
                }

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
Exemplo n.º 2
0
        public ActionResult Edit(DocumentWebServiceReference.Document document)
        {
            try
            {
                DocumentWebServiceReference.Document tmpDoc = document;
                if (Request.Files["file1"].FileName != string.Empty)
                {
                    byte[] buffer = new byte[Request.Files["file1"].ContentLength];
                    Request.Files["file1"].InputStream.Read(buffer, 0, buffer.Length);
                    document.Extension = Request.Files["file1"].FileName.Substring(Request.Files["file1"].FileName.LastIndexOf('.'));
                    document.File      = buffer;
                }
                else
                {
                    using (var service = new DocumentWebServiceReference.DocumentsService())
                    {
                        tmpDoc = service.GetDocumentById(document.Id, true);
                    }
                }

                document.CandidateIdSpecified = true;

                using (var service = new CandidateWebServiceReference.CandidatesService())
                {
                    document.CandidateId = service.GetCandidateByLogin(this.GetLogin()).Id;
                }

                using (var service = new DocumentWebServiceReference.DocumentsService())
                {
                    int  ID;
                    bool result;
                    service.SaveDocument(tmpDoc, document.CandidateId, true, document.Type, true, out ID, out result);
                }

                return(RedirectToAction("Index"));
            }
            catch (Exception e)
            {
                return(View());
            }
        }