コード例 #1
0
        public IActionResult UpdateDocument(DocumentPreview document)
        {
            var documentDTO = _mapper.Map <DocumentDTO>(document);

            if (documentDTO.Id == 0) //Save new document
            {
                _documentContext.Documents.Add(documentDTO);
            }
            else // Update existing
            {
                var existingDocument = _documentContext.Documents.Find(document.Id);

                // Переделать, вроде можно через маппер
                existingDocument.Name        = documentDTO.Name;
                existingDocument.ParentId    = documentDTO.ParentId;
                existingDocument.SubjectId   = documentDTO.SubjectId;
                existingDocument.AuthorId    = documentDTO.AuthorId;
                existingDocument.Description = documentDTO.Description;
                existingDocument.Text        = documentDTO.Text;

                _documentContext.Documents.Update(existingDocument);
            }

            _documentContext.SaveChanges();

            return(new OkResult());
        }
コード例 #2
0
        public IHttpActionResult PutDocument(int id, Document document)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != document.ID)
            {
                return(BadRequest());
            }

            db.Entry(document).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!DocumentExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
コード例 #3
0
        public ActionResult Create([Bind(Include = "DocumentID,Title,Author,Content")] Document document)
        {
            if (ModelState.IsValid)
            {
                db.Documents.Add(document);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(document));
        }
コード例 #4
0
        public async Task <IActionResult> OnPostUploadAsync(IFormFile formFile)
        {
            if (formFile != null && formFile.Length > 0)
            {
                if (formFile.ContentType != "application/pdf")
                {
                    return(BadRequest("Not a valid file type"));
                }
                if (formFile.Length > 5 * 1024 * 1024)
                {
                    return(BadRequest("File size is greater than 5 MB"));
                }

                Document document = new Document();
                document.ID       = Guid.NewGuid();
                document.Name     = formFile.FileName;
                document.Location = "/api/documents/" + formFile.FileName;
                document.Size     = (formFile.Length / (1024.00 * 1024)); //storing in mb
                using (var memoryStream = new MemoryStream())
                {
                    await formFile.CopyToAsync(memoryStream);

                    document.Content = memoryStream.ToArray();
                }
                _context.Documents.Add(document);
                _context.SaveChanges();
            }

            return(Ok("Uploaded"));
        }
コード例 #5
0
 public void Delete(int registerId)
 {
     using (DocumentContext db = new DocumentContext())
     {
         Client clientToDelete = db.Clients.Find(registerId);
         db.Entry(clientToDelete).State = EntityState.Deleted;
         db.SaveChanges();
     }
 }
コード例 #6
0
 public void Delete(int userId)
 {
     using (DocumentContext db = new DocumentContext())
     {
         User userToDelete = db.Users.Find(userId);
         db.Entry(userToDelete).State = EntityState.Deleted;
         db.SaveChanges();
     }
 }
コード例 #7
0
 public RegisteredClient Create(CreateClient newRegister)
 {
     using (DocumentContext db = new DocumentContext())
     {
         Client clientEntity = newRegister.ToEntity();
         db.Clients.Add(clientEntity);
         db.SaveChanges();
         return(clientEntity.ToDTO());
     }
 }
コード例 #8
0
        public void DeleteDocument(Guid documentId)
        {
            var document = _documentContext.Documents.FirstOrDefault(x => x.Id.Equals(documentId));

            if (document != null)
            {
                _documentContext.Documents.Remove(document);
                _documentContext.SaveChanges();
            }
        }
コード例 #9
0
 public RegisteredUser Create(CreateUser createUserData)
 {
     using (DocumentContext db = new DocumentContext())
     {
         User userEntity = createUserData.ToEntity();
         db.Users.Add(userEntity);
         db.SaveChanges();
         return(userEntity.ToDTO());
     }
 }
コード例 #10
0
 static void Main(string[] args)
 {
     using (var c = new DocumentContext())
     {
         c.Documents.Add(new Document {
             Id = 1
         });
         c.SaveChanges();
     }
 }
コード例 #11
0
        public void CreateDocument(Document document)
        {
            DocumentDB.Documents.Add(document);
            DocumentDB.SaveChanges();

            DocumentStatus documentStatus = new DocumentStatus {
                DocumentId = document.DocumentId, StatusId = document.DocumentId, Date = DateTime.Now
            };

            DocumentDB.DocumentStatuses.Add(documentStatus);
            DocumentDB.SaveChanges();

            Status status = new Status {
                StatusId = documentStatus.StatusId, Name = "CREATED"
            };

            DocumentDB.Statuses.Add(status);

            DocumentDB.SaveChanges();
        }
コード例 #12
0
        public JsonResult Add(DocumentViewModel documentViewModel)
        {
            Document document = MainAnalyzer.ParseText(documentViewModel.Text, db);

            db.Documents.Add(document);


            db.SaveChanges();
            document.Words = document.Words.OrderBy(x => x.Index).ToList();
            return(Json(document));
        }
コード例 #13
0
        public int Insert(DOCUS_ASM_ASSIGNMENTS assignmentRequest)
        {
            try
            {
                // Your code...
                // Could also be before try if you know the exception occurs in SaveChanges

                _context.DOCUS_ASM_ASSIGNMENTS.Add(assignmentRequest);
                _context.SaveChanges();
                var docusAsmAssignments = _context.DOCUS_ASM_ASSIGNMENTS.Where(
                    reqId => reqId.ACCOUNT_NUMBER == assignmentRequest.ACCOUNT_NUMBER)
                                          .OrderByDescending(x => x.ASSIGNMENT_ID)
                                          .FirstOrDefault();
                if (docusAsmAssignments != null)
                {
                    var result =
                        docusAsmAssignments.ASSIGNMENT_ID;
                    return(result);
                }
            }
            catch (DbEntityValidationException e)
            {
                foreach (var eve in e.EntityValidationErrors)
                {
                    Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                      eve.Entry.Entity.GetType().Name, eve.Entry.State);
                    foreach (var ve in eve.ValidationErrors)
                    {
                        Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                          ve.PropertyName, ve.ErrorMessage);
                    }
                }
                throw;
            }
            //_context.DOCUS_ASM_ASSIGNMENTS.Add(assignmentRequest);
            // _context.SaveChanges();
            // if (assignmentRequest != null)

            //     DateTime.Now, assignmentRequest.CREATED_BY, assignmentRequest.UPDATED_BY);
            return(0);
        }
コード例 #14
0
 public RegisteredClient Update(UpdateClient updateRegister)
 {
     using (DocumentContext db = new DocumentContext())
     {
         Client userToUpdate = db.Clients.Find(updateRegister.Id);
         userToUpdate.Email   = updateRegister.Email;
         userToUpdate.Address = updateRegister.Address;
         userToUpdate.Phone   = updateRegister.Phone;
         db.SaveChanges();
         return(userToUpdate.ToDTO());
     }
 }
コード例 #15
0
 public RegisteredUser Update(UpdateUser updateUserData)
 {
     using (DocumentContext db = new DocumentContext())
     {
         User userToUpdate = db.Users.Find(updateUserData.Id);
         userToUpdate.LastNames = updateUserData.LastNames;
         userToUpdate.Names     = updateUserData.Names;
         userToUpdate.Password  = updateUserData.Password;
         db.SaveChanges();
         return(userToUpdate.ToDTO());
     }
 }
コード例 #16
0
ファイル: HomeController.cs プロジェクト: rmmml/DocStore
        public ActionResult New(Document doc)
        {
            XmlWriter writer = XmlWriter.Create(Server.MapPath("/Files/" + doc.Title + ".xml"));

            writer.Close();
            doc.CreatedDate = DateTime.Now;
            doc.Author      = User.Identity.Name;
            doc.Location    = "/Files/" + doc.Title + ".xml";

            db.Documents.Add(doc);
            db.SaveChanges();

            return(RedirectToAction("Index"));
        }
コード例 #17
0
        public ActionResult Create(string ChangeTitle, string Beschreibung, string myFile)
        {
            Documents document = new Documents();

            document.DocumentName = myFile;
            document.DocumentPath = "C:/TestPath";
            document.UserName     = Environment.UserName;
            document.RequestDate  = DateTime.Now;

            _context.Documents.Add(document);
            _context.SaveChanges();

            return(RedirectToAction("Index", "Home"));
        }
コード例 #18
0
        public DocumentManagementAPITesting()
        {
            optionsBuilder = new DbContextOptionsBuilder <DocumentContext>();
            optionsBuilder.UseInMemoryDatabase(databaseName: "DocumentManagementDBTest");
            context       = new DocumentContext(optionsBuilder.Options);
            docController = new DocumentsController(context);
            Document document = new Document();

            document.ID       = Guid.NewGuid();
            document.Name     = "Test File.pdf";
            document.Location = "/api/documents/Test File.pdf";
            document.Size     = 100; //storing in mb
            context.Documents.Add(document);
            context.SaveChanges();
        }
コード例 #19
0
        private async void saveToDBToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (CheckIfFilenameInputEmpty())
            {
                return;
            }

            UpdateStatusLabel("Saving the file to the database...");
            try
            {
                await Task.Run(() =>
                {
                    using (DocumentContext documentContext = new DocumentContext())
                    {
                        if (documentContext.Documents.Any(d => d.Name == currentFilename && d.Extension == currentExtension))
                        {
                            DialogResult dialogResult =
                                MessageBox.Show(
                                    "The file with the same name has already been added to a database. \r\nDo you want to overwrite it?",
                                    "Record exists",
                                    MessageBoxButtons.YesNo);

                            if (dialogResult == DialogResult.No)
                            {
                                return;
                            }
                        }

                        Document document = new Document()
                        {
                            Name      = currentFilename,
                            Extension = currentExtension,
                            Contents  = textBox.Text
                        };

                        documentContext.Documents.AddOrUpdate(document);
                        documentContext.SaveChanges();

                        UpdateStatusLabel("File saved to the database.");
                    }
                });
            }
            catch
            {
                MessageBox.Show("Failed to save to the database.", "Error");
                UpdateStatusLabel("Failed to save to the database.");
            }
        }
コード例 #20
0
ファイル: Program.cs プロジェクト: IRonzin/RpcImportServer
        /// <summary>
        /// Кеширование.
        /// </summary>
        /// <param name="json1"></param>
        /// <param name="json3"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        private static Document CacheDocument(Json1 json1, Json3 json3, string data)
        {
            var doc = new Document()
            {
                Title        = json1.Title,
                Organization = json1.Organization_name,
                Topic        = json1.Topic,
                Identifier   = json1.Identifier,
                File         = new File()
                {
                    Data   = data,
                    Source = json3.Source,
                    Format = json3.Format,
                },
            };

            documentContext.Add(doc);
            documentContext.SaveChanges();
            return(doc);
        }
コード例 #21
0
        public ActionResult UploadFile(HttpPostedFileBase File, string poisk)
        {
            // Save file to Folder UploadedFiles //
            //if (File != null && File.ContentLength > 0)
            //{
            //    string _FileName = System.IO.Path.GetFileName(File.FileName);
            //    File.SaveAs(Server.MapPath("~/UploadedFiles/" +_FileName));
            //    ViewBag.Message = "Success";
            //}

            if (File != null && File.ContentLength > 0)
            {
                StreamReader reader = new StreamReader(File.InputStream);
                {
                    string searching = "";

                    while ((searching = reader.ReadLine()) != null)
                    {
                        string[] sentences = searching.Split(new char[] { '.' });
                        foreach (var sentence in sentences)
                        {
                            if (sentence.Contains(poisk))
                            {
                                char[] mass = sentence.ToCharArray();
                                Array.Reverse(mass);
                                string   output = new string(mass);
                                Document doc    = new Document();
                                doc.Text = output;
                                db.Docs.Add(doc);
                                db.SaveChanges();
                            }
                        }
                    }
                    reader.Close();
                }
            }

            return(RedirectToAction("Index"));
        }
コード例 #22
0
 public void Complete()
 {
     _context.SaveChanges();
 }
コード例 #23
0
ファイル: UnitOfWork.cs プロジェクト: yuliiapavlyk/newDocs
 public void Save()
 {
     db.SaveChanges();
 }
コード例 #24
0
 public void Insert(DOCUS_ASM_LOOKUP_REQUEST_TYPE requestTypeData)
 {
     _context.DOCUS_ASM_LOOKUP_REQUEST_TYPE.Add(requestTypeData);
     _context.SaveChanges();
 }
コード例 #25
0
 public void Insert(DOCUS_ASM_LOOKUP_PROCESSOR_NAME processorNameData)
 {
     _context.DOCUS_ASM_LOOKUP_PROCESSOR_NAME.Add(processorNameData);
     _context.SaveChanges();
 }
コード例 #26
0
 public void Insert(DOCUS_ASM_LOOKUP_REQUESTOR_NAME requestorNameData)
 {
     _context.DOCUS_ASM_LOOKUP_REQUESTOR_NAME.Add(requestorNameData);
     _context.SaveChanges();
 }
コード例 #27
0
 public void Insert(DOCUS_SUB_LOOKUP_FEE feeData)
 {
     _context.DOCUS_SUB_LOOKUP_FEE.Add(feeData);
     _context.SaveChanges();
 }
コード例 #28
0
 public void Insert(DOCUS_SUB_LOOKUP_REPRESENTATIVE representativeData)
 {
     _context.DOCUS_SUB_LOOKUP_REPRESENTATIVE.Add(representativeData);
     _context.SaveChanges();
 }
コード例 #29
0
 public void Insert(DOCUS_ASM_LOOKUP_PROCESSED_BY processedByData)
 {
     _context.DOCUS_ASM_LOOKUP_PROCESSED_BY.Add(processedByData);
     _context.SaveChanges();
 }
コード例 #30
0
ファイル: Program.cs プロジェクト: rogeralsing/linq-to-sqlxml
        private static void Main(string[] args)
        {
            var ctx = new DocumentContext("main");
            ctx.EnsureDatabaseExists();

            //var untyped = ctx.GetCollection("Customer");
            //dynamic c = new ExpandoObject();
            //c.Name = "Dynamic";
            //c.Address = new Address { Line1 = "a", ZipCode = "123", City = "b" };
            //c.Id = Guid.NewGuid();

            //untyped.Add(c);

            //var query = (
            //    from order in ctx.GetCollection<Order>().AsQueryable()
            //    where order.OrderTotal > 0
            //    //  where order.OrderDate < DateTime.Now
            //    where order.Status == OrderStatus.Shipped
            //    select order
            //    );

            ////touch the db
            //var x = query.Take(1).ToList();

            //Stopwatch sw = new Stopwatch();
            //Console.WriteLine("Starting...");
            //sw.Start();
            //var result = query.ToList();
            //sw.Stop();

            //Console.WriteLine("feteched {0} records", result.Count);
            ////foreach (var order in result)
            ////{
            ////    Console.WriteLine("{0}", order);
            ////}

            //Console.WriteLine(sw.Elapsed);
            //Console.ReadLine();
            //return;

            Stopwatch sw = new Stopwatch();
            Console.WriteLine("Starting...");
            sw.Start();
            for (int i = 0; i < 5000; i++)
            {
                //Console.WriteLine(i);
                var someCompany = new Customer
                                  {
                                      Address = new Address
                                                    {
                                                        City = "Stora mellösa",
                                                        Line1 = "Linfrövägen " + i,
                                                        State = "T",
                                                        ZipCode = "71572"
                                                    },
                                      Name = "Precio" + i,

                                  };

                ctx.GetCollection<Customer>().Add(someCompany);

                //var someOrder = new Order
                //                       {
                //                           CustomerId = Guid.NewGuid(),
                //                           OrderDate = DateTime.Now,
                //                           ShippingDate = DateTime.Now,
                //                           OrderDetails = new List<OrderDetail>() ,
                //                           ShippingAddress = new Address
                //                                                 {
                //                                                     City = "a",
                //                                                     Line1 = "b",
                //                                                     ZipCode = "c"
                //                                                 },
                //                           Status = OrderStatus.Shipped,
                //                       };
                //for (int j = 0; j < 1; j++)
                //{
                //    someOrder.OrderDetails.Add(new OrderDetail
                //    {
                //        ItemPrice = i,
                //        ProductNo = "x" + i,
                //        Quantity = i,
                //    });
                //}

                //ctx.GetCollection<Order>().Add(someOrder);
                ////var result = DocumentSerializer.Serialize(specialOrder);
                ////Console.WriteLine(result.ToString());
                ////ctx.GetCollection<Order>().Add(specialOrder);
                ////ctx.SaveChanges();
                ////var des = DocumentDeserializer.Deserialize(result);

                ////    var address = new Address()
                ////                      {
                ////                          City = "Örebro",
                ////                          Line1 = "blabla",
                ////                          ZipCode = "" + i ,
                ////                      };

                ////    ctx.GetCollection<Address>().Add(address);
                ////}

            }
            Console.WriteLine(sw.Elapsed);
            ctx.SaveChanges();
            Console.WriteLine(sw.Elapsed);

            Console.Read();
            //    Console.ReadLine();
        }
コード例 #31
0
ファイル: Program.cs プロジェクト: rogeralsing/linq-to-sqlxml
        private static void Main(string[] args)
        {
            var ctx = new DocumentContext("main");
            {
                var blogpost = new BlogPost()
                                   {
                                       Body = "gdfg",
                                       Topic = "fsdfs world",
                                   };

                blogpost.ReplyTo("Hej hej", "Roggan");
                blogpost.AddTag("NoSql");
                Console.WriteLine(blogpost.Id);
                ctx.GetCollection<BlogPost>().Add(blogpost);

                ctx.SaveChanges();
                Console.Read();
            }
            var query = from blogpost in ctx.GetCollection<BlogPost>().AsQueryable()
                                         where
                                             blogpost.Comments.Any(c => c.UserName == "Roggan") &&
                                             blogpost.CommentCount > 0
                                         select blogpost;

            List<BlogPost> result = query.ToList();

            foreach (BlogPost blogpost in result)
            {
                Console.WriteLine(blogpost.Topic);
            }
        }
コード例 #32
0
 public void Save()
 {
     _dbContext.SaveChanges();
 }