Exemple #1
0
        // GET: Work
        public async Task <ActionResult> Index()
        {
            var aspNetUser = await _aspNetUserRepository.GetByIdAsync(User.Identity.GetUserId());

            if (aspNetUser == null)
            {
                return(HttpNotFound());
            }

            var works = await _workRepository.GetAllByUserAsync(User.Identity.GetUserId());

            var projects = await _projectRepository.GetAllAsync();

            WorkListViewModel viewModel = Mapper.Map <IEnumerable <Work>, WorkListViewModel>(works)
                                          .Map(projects);

            return(View(viewModel));
        }
Exemple #2
0
        public ActionResult Details(int id)
        {
            var wl    = dc.WorkLists.Where(w => w.WorkListId == id).SingleOrDefault();
            var model = new WorkListViewModel
            {
                id          = wl.WorkListId,
                name        = wl.Name,
                user        = wl.User,
                dateCreated = wl.Date,
                isActive    = wl.IsActive,
                receipts    = wl.Receipts.Select(receipt => new ReceiptViewModel
                {
                    CompanyId = receipt.Company.CompanyId,
                    ReceiptId = receipt.ReceiptId,
                    BugNumber = receipt.UniqueNumber,
                    Articles  = receipt.Articles.Select(a => new ArticleViewModel
                    {
                        ArticleName = a.Name,
                        Price       = a.Price
                    }).ToList(),
                    Company = new CompanyViewModel
                    {
                        CompanyId   = receipt.Company.CompanyId,
                        Name        = receipt.Company.Name,
                        Address     = receipt.Company.Address,
                        Eik         = receipt.Company.Bulstat,
                        Description = receipt.Company.Description,
                        LeftNumber  = receipt.Company.LeftNumber,
                        RigthNumber = receipt.Company.RigthNumber
                    },
                    Operator = receipt.OperatorS,
                    Date     = receipt.Date,
                    DateF    = receipt.Date.ToString("dd-MM-yyyy hh:mm:ss")
                }).ToList()
            };


            return(View(model));
        }
Exemple #3
0
        public ActionResult generatePdf(int id)
        {
            var    wl  = dc.WorkLists.Where(w => w.WorkListId == id).SingleOrDefault();
            Random ran = new Random();

            wl.Receipts.ToList().ForEach(res => {
                var oldR = dc.Receipts.Where(tr => tr.Company.CompanyId == res.Company.CompanyId && tr.Date < res.Date).ToList();
                var newR = dc.Receipts.Where(tr => tr.Company.CompanyId == res.Company.CompanyId && tr.Date > res.Date).ToList();

                if (oldR.Count() == 0 && newR.Count == 0)
                {
                    res.OrderNumner = ran.Next(5600, 8900);
                    dc.SaveChanges();
                }
                else if (oldR.Count() > 0 && newR.Count == 0)
                {
                    res.OrderNumner = oldR.Max(rr => rr.OrderNumner) + ran.Next(12, 23);
                    dc.SaveChanges();
                }
                else if (oldR.Count() == 0 && newR.Count > 0)
                {
                    res.OrderNumner = newR.Min(rr => rr.OrderNumner) - ran.Next(12, 23);
                    dc.SaveChanges();
                }
                else if (oldR.Count() > 0 && newR.Count > 0)
                {
                    res.OrderNumner = ran.Next(oldR.Max(rr => rr.OrderNumner), newR.Min(rr => rr.OrderNumner));
                    dc.SaveChanges();
                }
            });

            var model = new WorkListViewModel
            {
                id          = wl.WorkListId,
                name        = wl.Name.Replace(" ", ""),
                user        = wl.User,
                dateCreated = wl.Date,
                isActive    = wl.IsActive,
                link        = GetBaseUrl() + "/Content/img/bg.png",
                receipts    = wl.Receipts.Select(receipt => new ReceiptViewModel
                {
                    CompanyId = receipt.Company.CompanyId,
                    Number    = receipt.OrderNumner.ToString("0000000"),
                    BugNumber = receipt.UniqueNumber,
                    ReceiptId = receipt.ReceiptId,
                    Articles  = receipt.Articles.Select(a => new ArticleViewModel
                    {
                        ArticleName = a.Name,
                        Price       = a.Price
                    }).ToList(),
                    Company = new CompanyViewModel
                    {
                        CompanyId   = receipt.Company.CompanyId,
                        Name        = receipt.Company.Name,
                        Address     = receipt.Company.Address,
                        Eik         = receipt.Company.Bulstat,
                        Description = receipt.Company.Description,
                        LeftNumber  = receipt.Company.LeftNumber,
                        RigthNumber = receipt.Company.RigthNumber
                    },
                    Operator = receipt.OperatorS,
                    Date     = receipt.Date,
                    DateF    = receipt.Date.ToString("dd-MM-yyyy hh:mm:ss")
                }).ToList()
            };

            Random r            = new Random();
            string securityCode = r.Next(1, 1000000).ToString("000000");

            var userID = User.Identity.GetUserId();
            var _user  = dc.Users.Where(u => u.Id == userID).SingleOrDefault();
            var name   = string.Format("{0}-{1}-{2}", wl.Name.Replace(" ", "") != "" ? wl.Name : "XXXXXX", DateTime.Now.ToString("dd.MM.yyyy"), securityCode);
            var url    = string.Format("{0}/Content/pdf/{1}.pdf", GetBaseUrl(), name);

            byte[] data = Hellper.PdfGenerator.GeneratePdf(model, Server.MapPath("~/Content/pdf/"));
            var    pdf  = new Pdf
            {
                Date         = DateTime.Now,
                Name         = name,
                securityCode = securityCode,
                User         = _user,
                url          = url
            };

            dc.Pdfs.Add(pdf);
            dc.SaveChanges();
            var path = Path.Combine(Server.MapPath("~/Content/pdf/"), name + ".pdf");

            System.IO.File.WriteAllBytes(path, data);

            return(RedirectToAction("Details", "pdf", new { id = pdf.PdfId }));
        }