public void GeneratePorotocolReport(Protocol protocol, Request request = null)
 {
     var filesRep = new FilesRepository();
     filesRep.GenerateProtocolReport(protocol, request);
 }
        public string GenerateRequest(Guid diaryId, int testingPeriod)
        {
            if(db.Diaries.Any(x => x.Id == diaryId))
            {
                Request request = new Request();
                request.Id = Guid.NewGuid();
                var date = DateTime.Now.ToUniversalTime();
                request.Date = date;
                request.DiaryId = diaryId;
                request.TestingPeriod = testingPeriod;

                try
                {
                    db.Requests.Add(request);
                    var filesRepository = new FilesRepository();
                    string charGenerated = filesRepository.GenerateRequestListReport(diaryId, date, testingPeriod);
                    db.SaveChanges();

                    return charGenerated;
                }
                catch(Exception ex)
                {
                    Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
                }
            }

            return string.Empty;
        }
        public ActionResponse RegenerateArchivedProtocol(ArchivedDiaryW adiary)
        {
            var response = new ActionResponse();

            try
            {
                var filesRep = new FilesRepository();
                filesRep.RegenerateProtocolReport(adiary);

                response.IsSuccess = true;
                response.SuccessMsg = "Успешно опресняване на архивирания протокол!";
            }
            catch (Exception exc)
            {
                Elmah.ErrorSignal.FromCurrentContext().Raise(exc);
                response.Error = ErrorFactory.UnableToRefreshArchivedProtocol;
            }

            return response;
        }
        public void Edit(DiaryW diaryW)
        {
            var diary = db.Diaries.Single(c => c.Id == diaryW.Id);
            diary.LetterNumber = diaryW.LetterNumber;
            diary.LetterDate = diaryW.LetterDate;
            diary.Contractor = diaryW.Contractor;
            diary.ClientId = diaryW.ClientId;

            //diary.Products.Clear();
            foreach (var item in diary.Products)
            {
                var pts = db.ProductTests.Where(pt => pt.ProductId == item.Id);
                db.ProductTests.RemoveRange(pts);
            }
            db.Products.RemoveRange(diary.Products);

            int i = 1;
            foreach (var item in diaryW.Products)
            {
                item.Id = Guid.NewGuid();
                item.DiaryId = diary.Id;
                item.Number = i;
                //item.Test = db.Tests.FirstOrDefault(x => x.Id == item.TestId);
                i++;

                foreach (var test in item.ProductTests)
                {
                    test.Id = Guid.NewGuid();
                    test.ProductId = item.Id;
                }

                diary.Products.Add(item);
            }

            db.SaveChanges();

            var request = diary.Requests.FirstOrDefault();
            if (request != null)
            {
                var filesRepository = new FilesRepository();
                string charGenerated = filesRepository.GenerateRequestListReport(diary.Id, request.Date, request.TestingPeriod ?? 0);
            }
        }