public Task <bool> DeleteFreeModelCopy(ModelCopy mc, int id)
 {
     return(Task.Factory.StartNew(() =>
     {
         _db.DeleteFreeModelCopy(mc, id);
         return true;
     }));
 }
Exemple #2
0
        public async Task <IdentityResult> DeleteFreeModelCopy(string id)
        {
            ModelCopy temp = new ModelCopy
            {
                modelID   = Int32.Parse(id),
                modelType = TypeEnum.Book
            };
            await _im.DeleteFreeModelCopy(temp, Int32.Parse(id));

            return(IdentityResult.Success);
        }
Exemple #3
0
 public Task <IdentityResult> DeleteFreeModelCopy(string id)
 {
     return(Task.Factory.StartNew(() =>
     {
         ModelCopy temp = new ModelCopy
         {
             modelID = Int32.Parse(id),
             modelType = TypeEnum.Magazine
         };
         _im.DeleteFreeModelCopy(temp, Int32.Parse(id));
         return IdentityResult.Success;
     }));
 }
        public async Task <List <PrintedLog> > GetLogs()
        {
            var logs = await _identityMap.GetAllLogs();

            List <PrintedLog>         results = new List <PrintedLog>();
            List <Task <PrintedLog> > tasker  = new List <Task <PrintedLog> >(logs.Count);

            tasker.AddRange(logs.Select(log => GetPLog(log)));

            foreach (var task in tasker)
            {
                results.Add(await task);
            }

            return(results);

            async Task <PrintedLog> GetPLog(Log log)
            {
                ModelCopy modelCopy = await _identityMap.FindModelCopy(log.ModelCopyID).ConfigureAwait(false);

                string modelName = "";

                switch (modelCopy.modelType)
                {
                case TypeEnum.Book:
                    modelName = (await _identityMap.FindBook(modelCopy.modelID))?.Title;
                    break;

                case TypeEnum.Magazine:
                    modelName = (await _identityMap.FindMagazine(modelCopy.modelID))?.Title;
                    break;

                case TypeEnum.Movie:
                    modelName = (await _identityMap.FindMovie(modelCopy.modelID))?.Title;
                    break;

                case TypeEnum.Music:
                    modelName = (await _identityMap.FindMusic(modelCopy.modelID))?.Title;
                    break;
                }

                Client client = await _clientManager.FindByIdAsync(log.ClientID.ToString());

                return(new PrintedLog(client.FirstName + " " + client.LastName, log.Transaction,
                                      modelCopy.modelType, modelName, log.ModelCopyID, log.TransactionTime));
            }
        }
Exemple #5
0
 //Delete ModelCopy
 public Task <IdentityResult> DeleteAsync(ModelCopy modelCopy)
 {
     if (modelCopy != null)
     {
         return(Task.Factory.StartNew(() =>
         {
             _unitOfWork.RegisterDeleted(modelCopy);
             return IdentityResult.Success;
         }));
     }
     return(Task.Factory.StartNew(() =>
     {
         return IdentityResult.Failed(new IdentityError {
             Description = "modelCopy was null"
         });
     }));
 }
Exemple #6
0
        public async Task <ModelCopy> FindByIdAsync(int modelCopyId)
        {
            ModelCopy modelCopy = await _im.FindModelCopy((modelCopyId));

            return(modelCopy);
        }
Exemple #7
0
        public async Task <List <PrintedLog> > SearchLogsAsync(string clientName, string CopyID,
                                                               string type, string ModelId, string dateTime1, string dateTime2,
                                                               bool exactTime, string transac)
        {
            List <PrintedLog> results = new List <PrintedLog>();

            List <List <Log> > logs = new List <List <Log> >();

            List <Task <List <Log> > > logsTasks = new List <Task <List <Log> > >();


            if (!string.IsNullOrEmpty(clientName))
            {
                var clients = await _clientManager.FindClientsByNameAsync(clientName);

                foreach (var client in clients)
                {
                    logsTasks.Add(SearchLogsByClientIDAsync(client.clientId));
                }
            }

            if (!string.IsNullOrEmpty(CopyID))
            {
                logsTasks.Add(SearchLogsByCopyIDAsync(int.Parse(CopyID)));
            }

            if (!string.IsNullOrEmpty(type) && !string.IsNullOrEmpty(ModelId))
            {
                Enum.TryParse(type, out TypeEnum m_type);
                logsTasks.Add(SearchLogsByModelTypeAndIdAsync(m_type, int.Parse(ModelId)));
            }

            if (!string.IsNullOrEmpty(dateTime1))
            {
                if (string.IsNullOrEmpty(dateTime2))
                {
                    logsTasks.Add(SearchLogsByDateAsync(DateTime.Parse(dateTime1), exactTime));
                }
                else
                {
                    logsTasks.Add(SearchLogsByPeriodAsync(DateTime.Parse(dateTime1), DateTime.Parse(dateTime2), exactTime));
                }
            }

            if (!string.IsNullOrEmpty(transac))
            {
                Enum.TryParse(transac, out TransactionType t_type);
                logsTasks.Add(SearchLogsByTransactionAsync(t_type));
            }

            foreach (var lt in logsTasks)
            {
                logs.Add(await lt);
            }
            if (logs.Count > 0)
            {
                HashSet <Log> intersection = new HashSet <Log>(logs[0], new SearchTransactionComparer());
                for (int i = 1; i < logs.Count; i++)
                {
                    intersection.IntersectWith(logs[i]);
                }

                var lTasks = new List <Task <PrintedLog> >(intersection.Count);
                lTasks.AddRange(intersection.Select(log => GetPLog(log)));

                foreach (var lTask in lTasks)
                {
                    results.Add(await lTask);
                }
            }
            return(results);

            async Task <PrintedLog> GetPLog(Log log)
            {
                ModelCopy modelCopy = await _im.FindModelCopy(log.ModelCopyID).ConfigureAwait(false);

                string modelName = "";

                switch (modelCopy.modelType)
                {
                case TypeEnum.Book:
                    modelName = (await _im.FindBook(modelCopy.modelID))?.Title;
                    break;

                case TypeEnum.Magazine:
                    modelName = (await _im.FindMagazine(modelCopy.modelID))?.Title;
                    break;

                case TypeEnum.Movie:
                    modelName = (await _im.FindMovie(modelCopy.modelID))?.Title;
                    break;

                case TypeEnum.Music:
                    modelName = (await _im.FindMusic(modelCopy.modelID))?.Title;
                    break;
                }

                Client client = await _clientManager.FindByIdAsync(log.ClientID.ToString());

                return(new PrintedLog(client.FirstName + " " + client.LastName, log.Transaction,
                                      modelCopy.modelType, modelName, log.ModelCopyID, log.TransactionTime));
            }
        }