Esempio n. 1
0
        public async Task <IActionResult> OnPostAsync()
        {
            {
                var car = new Car()
                {
                    Id          = 0,
                    CarId       = bUYACAR.CarID,
                    Insurance   = bUYACAR.Insurance.Value,
                    ModelId     = bUYACAR.ModelId,
                    MoreDetails = bUYACAR.moreDetails,
                    Owener      = bUYACAR.CarOwener,
                };
                var salePerson = new SalePerson()
                {
                    Adress   = bUYACAR.SaleAdress,
                    Name     = bUYACAR.SaleName,
                    Phone    = bUYACAR.SalePhone,
                    Idnumber = bUYACAR.IDNumber,
                    IdPhoto  = await Uplode(bUYACAR.IdPhoto, "ID")
                };
                var outcome = new Outcome()
                {
                    Price = bUYACAR.PriceOutcome
                };
                int OutcomeId = _outcome.AddOutcome(outcome).Result;


                var buy = new Buy()
                {
                    Date       = DateTime.Today,
                    CarId      = await _car.AddCar(car),
                    CustomerId = await _saleperson.AddSalePerson(salePerson),
                };
                var buyrecords = new BuyRecords()
                {
                    BuyId     = _buy.AddBuy(buy).Result,
                    OutcomeId = OutcomeId,
                    PartnerId = 1
                };
                await _buyrecord.AddBuyRecords(buyrecords);

                List <cc> dd = JsonConvert.DeserializeObject <List <cc> >(System.IO.File.ReadAllText("C:\\Users\\wwwmu\\source\\repos\\ManegmentSystems\\ManegmentSystems\\wwwroot\\data.json"));

                await _cash.AddCashAsync(new Cash()
                {
                    Amount       = bUYACAR.CashAmount[0],
                    Arrested     = true,
                    OutcomeId    = OutcomeId,
                    IncomeId     = null,
                    DateArrested = DateTime.Today
                });

                for (int i = 1; i < bUYACAR.CashAmount.Count - 1; i++)

                {
                    await _cash.AddCashAsync(new Cash()
                    {
                        Amount    = bUYACAR.CashAmount[i],
                        Arrested  = false,
                        OutcomeId = OutcomeId,
                        IncomeId  = null
                    });
                }
                for (int i = 0; i < dd.Count; i++)

                {
                    if (_check[dd[i].Id] == null)
                    {
                        _check.AddCheck(new Check()
                        {
                            Amount    = dd[i].Amount,
                            OutcomeId = OutcomeId,
                            Name      = dd[i].Name,
                            DueDate   = DateTime.Parse(dd[i].DueDate),
                            IncomeId  = null,

                            Photo = dd[i].files
                        });
                    }
                    else
                    {
                        var m = _check[dd[i].Id];
                        m.OutcomeId = OutcomeId;
                        await _check.UpdateCheck(dd[i].Id, m);
                    }
                }
            }
            callproc cc = new callproc();

            cc.updateCapitalShare(this.User.FindFirst(ClaimTypes.NameIdentifier).Value);
            cc = null;

            return(RedirectToPage("/gallary"));
        }