Пример #1
0
        public IActionResult Delete()
        {
            MongoAccessor dbAccessor = new MongoAccessor();

            dbAccessor.deleteAll(MongoAccessor.APPOINTMENTCOLLECTION);

            return(View());
        }
 /// <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"));
        }
 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;
 }