コード例 #1
0
        public IActionResult Delete()
        {
            MongoAccessor dbAccessor = new MongoAccessor();

            dbAccessor.deleteAll(MongoAccessor.APPOINTMENTCOLLECTION);

            return(View());
        }
コード例 #2
0
 /// <summary>
 /// 保存存储媒介的配置
 /// </summary>
 public void Save()
 {
     if (this.StorageMedia == StorageMediaType.MySQL ||
         this.StorageMedia == StorageMediaType.SQLServer)
     {
         var config = (RelationDatabaseConfigure)this;
         MongoAccessor.Insert <RelationDatabaseConfigure>(config);
     }
 }
コード例 #3
0
        public virtual IList <TEntity> GetList(IEnumerable <int> ids)
        {
            QueryComplete query = Query.In("_id", BsonArray.Create(ids));

            return(MongoAccessor.GetCollection <TEntity>().FindAs <TEntity>(query).ToList());
        }
コード例 #4
0
 public virtual TEntity Get(object id)
 {
     return(MongoAccessor.GetCollection <TEntity>().FindOneByIdAs <TEntity>(BsonValue.Create(id)));
 }
コード例 #5
0
 public virtual ActionResult <ResultKey, object> Delete(TEntity entity)
 {
     MongoAccessor.Delete(entity);
     return(new ActionResult <ResultKey, object>());
 }
コード例 #6
0
 public virtual ActionResult <ResultKey, TEntity> Create(TEntity entity)
 {
     MongoAccessor.Insert <TEntity>(entity);
     return(new ActionResult <ResultKey, TEntity>());
 }
コード例 #7
0
        public async Task <IActionResult> Post(IFormFile file)
        {
            long size = file.Length;

            //Get a place to store the temp file on the server
            var filePath = Path.GetTempFileName();

            if (file.Length > 0)
            {
                using (var stream = new FileStream(filePath, FileMode.Create))
                {
                    await file.CopyToAsync(stream);
                }
            }

            //Do stuff with file into mongo
            List <AppointmentModel> appointmentsToInsert = new List <AppointmentModel>();

            try
            {
                using (StreamReader reader = new StreamReader(filePath))
                {
                    String headerLine = reader.ReadLine();
                    String line;
                    while ((line = reader.ReadLine()) != null)
                    {
                        AppointmentModel newAppointment  = new AppointmentModel();
                        String[]         seperatedValues = line.Split('|');

                        if (seperatedValues.Length == 5)
                        {
                            newAppointment.LastName      = seperatedValues[0];
                            newAppointment.FirstName     = seperatedValues[1];
                            newAppointment.CalendarName  = seperatedValues[2];
                            newAppointment.StartDateTime = DateTime.ParseExact(seperatedValues[3],
                                                                               "yyyy-MM-dd HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture);
                            newAppointment.EndDateTime = DateTime.ParseExact(seperatedValues[4], "yyyy-MM-dd HH:mm:ss",
                                                                             System.Globalization.CultureInfo.InvariantCulture);
                            newAppointment.Reason = "";
                        }
                        else if (seperatedValues.Length == 6)
                        {
                            newAppointment.LastName      = seperatedValues[0];
                            newAppointment.FirstName     = seperatedValues[1];
                            newAppointment.CalendarName  = seperatedValues[2];
                            newAppointment.StartDateTime = DateTime.ParseExact(seperatedValues[3],
                                                                               "yyyy-MM-dd HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture);
                            newAppointment.EndDateTime = DateTime.ParseExact(seperatedValues[4], "yyyy-MM-dd HH:mm:ss",
                                                                             System.Globalization.CultureInfo.InvariantCulture);
                            newAppointment.Reason = seperatedValues[5];
                        }

                        appointmentsToInsert.Add(newAppointment);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("The file could not be read:");
                Console.WriteLine(e.Message);
            }

            MongoAccessor database = new MongoAccessor();

            database.addManyRecords(appointmentsToInsert, MongoAccessor.APPOINTMENTCOLLECTION); //This method is async so the ui doesn't freeze while data is put in the database. No need for an await becuase we don't need to wait for any data(as their is no return)


            return(RedirectToAction("SaveGood", "Home"));
        }
コード例 #8
0
 public MessageExtractor(PublishMessage publisher, MongoAccessor accessor, ILogger <MessageExtractor> logger)
 {
     _logger    = logger;
     _publisher = publisher;
     _accessor  = accessor;
 }
コード例 #9
0
 public DataController(MongoAccessor accessor, PublishMessage publisher)
 {
     _accessor  = accessor;
     _publisher = publisher;
 }