示例#1
0
        public void AddOffer(string debtor, System.Guid offerid)
        {
            ICollection <Offers>           offers;
            ICollection <EstimateConnects> Connect;

            using (var context = new DataBaseContext())
            {
                offers = context.Offer
                         .Include(offermodel => offermodel.Estimate)
                         .Include(user => user.CreatedBy)
                         .Include(user => user.UpdatedBy)
                         .ToList();

                Connect = context.EstimateConnects
                          .Include(line => line.EstimateLines)
                          .ToList();
            }
            var offer      = offers.FirstOrDefault(x => x.Id.Equals(offerid));
            var guid       = offer.Estimate.Id;
            var estimateid = Guid.Parse(guid.ToString());
            var estimate   = EstimateRepository.Find(estimateid);
            var lines      = Connect.Where(x => x.Estimate.Id == estimate.Id).ToList();

            var debtornumber = Regex.Replace(debtor, "[^0-9.]", "");

            var client       = new RestClient(ApiUrl);
            var request      = new RestRequest("/apiv2/api.php", Method.POST);
            var InvoiceLines = new List <Dictionary <string, string> >();

            foreach (var item in lines)
            {
                var line = new Dictionary <string, string>
                {
                    { "Description", item.EstimateLines.Specification },
                    { "PriceExcl", item.EstimateLines.TotalCost.ToString() }
                };
                InvoiceLines.Add(line);
            }
            var invoice = new Invoice
            {
                api_key    = ApiKey,
                controller = "invoice",
                action     = "add",
                Debtor     = debtornumber.ToString(),

                Concept      = 0,
                InvoiceLines = InvoiceLines
            };

            request.RequestFormat = DataFormat.Json;
            request.AddJsonBody(invoice);

            var response = client.Execute <WeFactResponseModel>(request);
            var offerte  = OfferRepository.Find(offerid);

            OfferRepository.SaveChanges();
            EditWefactLines(response.Data.Invoice.InvoiceLines, offerid);
        }
示例#2
0
        public void EditWefactLines(List <Dictionary <string, string> > invoicelines, Guid id)
        {
            ICollection <Offers>           offers;
            ICollection <EstimateConnects> Connect;

            using (var context = new DataBaseContext())
            {
                offers = context.Offer
                         .Include(offermodel => offermodel.Estimate)
                         .Include(user => user.CreatedBy)
                         .Include(user => user.UpdatedBy)
                         .ToList();

                Connect = context.EstimateConnects
                          .Include(line => line.EstimateLines)
                          .ToList();
            }

            var offer       = offers.FirstOrDefault(x => x.Id.Equals(id));
            var estimate    = EstimateRepository.Find(offer.Estimate.Id.ToString());
            var lineconnect = Connect.Where(x => x.Estimate.Id == estimate.Id).ToList();

            foreach (var line in invoicelines)
            {
                foreach (var item in line)
                {
                    if (item.Key == "Identifier")
                    {
                        foreach (var connects in lineconnect)
                        {
                            var lines = EstimateLinesRepository.Find(connects.EstimateLines.Id);
                            for (int i = 0; i < lineconnect.Count; i++)
                            {
                                lines.WefactIdentifier = int.Parse(item.Value);
                                EstimateLinesRepository.SaveChanges();
                            }
                        }
                    }
                }
            }
        }
示例#3
0
 public OfferController(IRepository <Offers> offerrepository,
                        IRepository <Users> userrepository,
                        IRepository <Offers> offerrepoitory,
                        IRepository <Estimates> estimaterepository,
                        IRepository <EstimateLines> estimatlinesrepository,
                        IRepository <EstimateConnects> estimateconnectsrepository,
                        IRepository <Settings> settingsrepository,
                        IConnector wefactConnector,
                        IHostingEnvironment env,
                        ITemplateService templateservice,
                        IConverter converterService)
 {
     OfferRepository            = (OfferRepository)offerrepository;
     UserRepository             = (UsersRepository)userrepository;
     EstimateRepository         = (EstimateRepository)estimaterepository;
     EstimateLinesRepository    = (EstimateLinesRepository)estimatlinesrepository;
     EstimateConnectsRepository = (EstimateConnectsRepository)estimateconnectsrepository;
     SettingsRepository         = (SettingsRepository)settingsrepository;
     Wefactconnector            = (WeFactConnector)wefactConnector;
     TemplateService            = templateservice;
     Environment      = env;
     ConverterService = converterService;
 }
示例#4
0
 public EstimateServices()
 {
     _estimateRepository = new EstimateRepository();
 }