示例#1
0
 public static async Task<List<DbWorkingTasks>> GetClientsTasks(string _shortId)
 {
     DataContext dataContex = new DataContext();
     ShowMessageClass message = new ShowConsoleMessage();
     try
     {
         var result = await dataContex.WorkingTasks.Find<DbWorkingTasks>((x) => x.ShortEoClientId==_shortId).ToListAsync();
         if (result.Count == 0)
             throw new NotImplementedException("Мы не смогли найти клиента с таким ID!");
         return result;
     }
     catch (MongoException ex)
     {
         throw new NotImplementedException($"Внимание!MongoDb ОШИБКА {ex.HResult}: {ex.Message}\nДанные: {ex.Data}");            
     }
 }
示例#2
0
        public static async Task<bool> NewEoTask(string _title, string _task, string _from, string _to, string _shortId, double _hours)
        {
            ShowMessageClass message = new ShowConsoleMessage();
            DataContext dataContex = new DataContext();
            DbWorkingTasks newTask = new DbWorkingTasks
            {
                _id = ObjectId.GenerateNewId(),
                ShortEoClientId = _shortId,
                Title = _title,
                PutTime = DateTime.Now.ToLocalTime(),
                TillDone = DateTime.Now.AddHours(_hours),
                To = _to,
                From = _from,
                IsDone = false,
                Messages = new List<EoMessages>(),
                Work = new List<EoWork>(),
                Task = _task
            };
            try
            {
                await dataContex.WorkingTasks.InsertOneAsync(newTask);
                message.ShowMessage($"Задача {_to} для {_shortId} поставлена!");
                return true;
            }
            catch (Exception)
            {
                throw;
            }

        }
示例#3
0
 //TODO: Разобраться с отловлей ошибок
 public static async Task<List<DbWorkingTasks>> GetTasks()
 {
     DataContext dataContex = new DataContext();
     ShowMessageClass message = new ShowConsoleMessage();
     try
     {
         var result = await dataContex.WorkingTasks.Find<DbWorkingTasks>((x) => true).ToListAsync();
         if (result.Count == 0)
             throw new NotImplementedException("Список задач пуст!");
         return result;
     }
     catch (MongoException ex)
     {
         throw new NotImplementedException($"Внимание!MongoDb ОШИБКА {ex.HResult}: {ex.Message}\nДанные: {ex.Data}");
     }
 }
示例#4
0
 public static async Task<bool> AddMessageToEoClient(string shortID, string message)
 {
     ShowMessageClass showMessage = new ShowConsoleMessage();
     var dataContex = new DataContext();
     var _message = new EoMessages();
     _message.From = "Kobelev"; // от кого
     _message.To = "Handogka"; // кому
     _message.Message = message;
     _message.PutDate = DateTime.Now.ToLocalTime();
     var findResult = await dataContex.EoClients.Find<EOData>((x) => x.Short_Id == shortID).FirstOrDefaultAsync();
     if (findResult.Message == null)
     {
         findResult.Message = new List<EoMessages>();
         findResult.Message.Add(_message);
         var replaceResult = await dataContex.EoClients.ReplaceOneAsync<EOData>((x) => x.Short_Id == findResult.Short_Id, findResult);
         if (replaceResult.ModifiedCount != 0)
         {
             showMessage.ShowMessage("Сообщеине добавленно");
             return true;
         }
         else
         {
             showMessage.ShowMessage("Сообщеине добавленно");
             return false;
         }
     }
     else
     {
         var builder = Builders<EOData>.Update.Push("Message", _message);
         var result = await dataContex.EoClients.UpdateOneAsync<EOData>((x) => x.Short_Id == shortID, builder);
         if (result.ModifiedCount != 0)
         {
             return true;
         }
         else
         {
             return false;
         }
     }
 }
示例#5
0
        //TODO: Добавить проверку на не корректные Value
        public static async Task<MyReplaceOneResult> DoUpdateEoClients(List<EOData> _data)
        {
            MyReplaceOneResult result = new MyReplaceOneResult();
            var dataContext = new DataContext();
            try
            {
                foreach (var item in _data)
                {
                    var update = Builders<EOData>.Update.Set((x) => x.Accountent, item.Accountent)
                                                                    .Set((x) => x.Agent, item.Agent)
                                                                    .Set((x) => x.Name, item.Name)
                                                                    .Set((x) => x.INN, item.INN)
                                                                    .Set((x) => x.Email, item.Email)
                                                                    .Set((x) => x.Mobile, item.Mobile)
                                                                    .Set((x) => x.ES, item.ES)
                                                                    .Set((x) => x.PFR, item.PFR)
                                                                    .Set((x) => x.Notification, item.Notification)
                                                                    .Set((x) => x.Partner, item.Partner)
                                                                    .Set((x) => x.LastUpdate, item.LastUpdate)
                                                                    .Set((x) => x.DateStart, item.DateStart)
                                                                    .Set((x) => x.DateEnd, item.DateEnd)
                                                                    .Set((x) => x.Type, item.Type);

                    var temp = await dataContext.EoClients.UpdateOneAsync<EOData>(x => x._id == item._id, update);
                    result.MatchedCount += temp.MatchedCount;
                    result.ModifiedCount += temp.ModifiedCount;
                }
            }
            catch (Exception)
            {
                throw;
            }
            return result;
        }
示例#6
0
 //TODO: обработать ошибки
 public async Task<List<EOData>> CheckUpdateForClients()
 {
     if (Data == null) throw new Exception($"Ошибка: CheckUpdateForClients(): Данные с сервера не были получены!\nИнициализируйте GetDataFromServer()");
     List<EOData> updatedData = new List<EOData>();
     object _lock = new object();
     var dataContext = new DataContext();
     var result = await dataContext.EoClients.Find(x => true).ToListAsync();
     Parallel.ForEach(Data.Rows, item =>
     {
         foreach (var itm in result)
         {
             if (itm._id == item._id)
             {
                 if (!itm.Equals(item))
                     lock (_lock)
                         updatedData.Add(item);
             }
         }
     });
     return updatedData;
 }
示例#7
0
 //TODO: обработать ошибки
 public async Task<List<EOData>> CheckAndUpdateForClients()
 {
     if (Data == null) throw new Exception($"Ошибка: CheckAndUpdateForClients(): Данные с сервера не были получены!\nИнициализируйте GetDataFromServer()");
     List<EOData> updatedData = new List<EOData>();
     object _lock = new object();
     var dataContext = new DataContext();
     var result = await dataContext.EoClients.Find(x => true).ToListAsync();
     Parallel.ForEach(Data.Rows, item =>
     {
         foreach (var itm in result)
         {
             if (itm._id == item._id)
             {
                 if (!itm.Equals(item))
                 {
                     lock (_lock)
                     {
                         var update = Builders<EOData>.Update.Set((x) => x.Accountent, item.Accountent)
                                                             .Set((x) => x.Agent, item.Agent)
                                                             .Set((x) => x.Name, item.Name)
                                                             .Set((x) => x.INN, item.INN)
                                                             .Set((x) => x.Email, item.Email)
                                                             .Set((x) => x.Mobile, item.Mobile)
                                                             .Set((x) => x.ES, item.ES)
                                                             .Set((x) => x.PFR, item.PFR)
                                                             .Set((x) => x.Notification, item.Notification)
                                                             .Set((x) => x.Partner, item.Partner)
                                                             .Set((x) => x.LastUpdate, item.LastUpdate)
                                                             .Set((x) => x.DateStart, item.DateStart)
                                                             .Set((x) => x.DateEnd, item.DateEnd)
                                                             .Set((x) => x.Type, item.Type);
                                                             
                         dataContext.EoClients.UpdateOne<EOData>(x => x._id == itm._id, update);
                         updatedData.Add(item);
                     }
                 }
                 break;
             }
         }
     });
     return updatedData;
 }
示例#8
0
 //TODO: обработать ошибки
 public async Task<List<EOData>> AddEoClientsDb()
 {
     if (Data == null) throw new Exception($"Ошибка: GetDataFromServer(): Данные с сервера не были получены!\nИнициализируйте GetDataFromServer()");
     List<EOData> dataResult = new List<EOData>();
     var dataContext = new DataContext();
     var dataFromDB = await dataContext.EoClients.Find(new BsonDocument()).ToListAsync();
     if (dataFromDB.Count != 0)
     {
         foreach (var item in Data.Rows)
         {
             var result = dataContext.EoClients.Find(x => x._id == item._id).FirstOrDefault();
             if (result == null)
             {
                 dataContext.EoClients.InsertOne(item);
                 dataResult.Add(item);
             }
         }
     }
     else
     {
         foreach (var item in Data.Rows)
         {
             dataContext.EoClients.InsertOne(item);
             dataResult.Add(item);
         }
     }
     return dataResult;
 }