Exemple #1
0
        //public async Task<DealerResponse> GetPost(long request)
        //{
        //    DealerResponse response = new DealerResponse();

        //    return response;
        //}

        public async Task <DealerResponse> UpdatePost(DealerRequest request)
        {
            DealerResponse response = new DealerResponse();

            try
            {
                Dealer dealer = await dep.GetPost(request.ID);

                dealer.KotaId        = request.KotaID;
                dealer.Kode          = request.Kode;
                dealer.Name          = request.Name;
                dealer.Alamat        = request.Alamat;
                dealer.Telepon       = request.Telepon;
                dealer.PejabatDealer = request.PejabatDealer;
                dealer.Modified      = DateTime.Now;
                dealer.ModifiedBy    = request.UserName;

                if (await dep.UpdatePost(dealer))
                {
                }
                else
                {
                    response.IsSuccess = false;
                    response.Message   = "Update Failed";
                }
            }
            catch (Exception ex)
            {
                log.Error(ex);
                response.IsSuccess = false;
                response.Message   = ex.ToString();
            }

            return(response);
        }
Exemple #2
0
        public async Task <DealerResponse> AddAuctionBundle(AuctionBundle auctionBundle)
        {
            DealerResponse response = new DealerResponse();
            List <object>  payload  = new List <object>();

            payload.Add(auctionBundle);
            double numberToBuy             = double.Parse(auctionBundle.Number, System.Globalization.CultureInfo.InvariantCulture);
            List <AuctionBundleForDb> list = await GetAuctionBundles();

            AuctionBundleForDb bundleForSymbol = await GetAuctionBundleForSymbol(auctionBundle.Symbol, App.User);

            if (bundleForSymbol == null)
            {
                AuctionBundleForDb dbBundle = new AuctionBundleForDb();
                dbBundle.Number      = double.Parse(auctionBundle.Number, System.Globalization.CultureInfo.InvariantCulture);
                dbBundle.MedianValue = auctionBundle.CloseValueAtDateBought;
                dbBundle.Symbol      = auctionBundle.Symbol;
                dbBundle.Name        = auctionBundle.Name;
                dbBundle.PersonID    = App.User.Id;
                response             = App.MiddleDealer.OnEvent(Databases.MessageAction.AddedAuctionBundle, payload);
                if (response == DealerResponse.Success)
                {
                    await connection.InsertAsync(dbBundle);
                }
            }
            else
            {
                payload.Add(bundleForSymbol);
                response = App.MiddleDealer.OnEvent(Databases.MessageAction.AddedAuctionBundle, payload);
            }



            return(response);
        }
Exemple #3
0
        public async Task <DealerResponse> DeletePost(long ID, string username)
        {
            DealerResponse response = new DealerResponse();

            try
            {
                if (await dep.DeletePost(ID, username) > 0)
                {
                    response.IsSuccess = true;
                    response.Message   = "Delete Success";
                }
                else
                {
                    response.IsSuccess = false;
                    response.Message   = "Delete Failed";
                }
            }
            catch (Exception ex)
            {
                log.Error(ex);
                response.IsSuccess = false;
                response.Message   = ex.ToString();
            }

            return(response);
        }
Exemple #4
0
        public async Task <DealerResponse> GetDealerByIdAsync(string datasetId, int dealerId)
        {
            var response = await _httpclient.GetAsync($"{_baseUrl}/{datasetId}/dealers/{dealerId}");

            DealerResponse dto = await response.Content.ReadAsAsync <DealerResponse>();

            return(dto);
        }
Exemple #5
0
        public async Task <DealerResponse> GetAll()
        {
            DealerResponse resp = new DealerResponse();

            try
            {
                string bearer   = Request.HttpContext.Request.Headers["Authorization"];
                string token    = bearer.Substring("Bearer ".Length).Trim();
                string username = string.Empty;
                if (string.IsNullOrEmpty(token))
                {
                    resp.IsSuccess = false;
                    resp.Message   = "You don't have access.";
                    return(resp);
                }

                username = sec.ValidateToken(token);
                if (username == null)
                {
                    Response.HttpContext.Response.Cookies.Append("access_token", "", new CookieOptions()
                    {
                        Expires = DateTime.Now.AddDays(-1)
                    });
                    resp.IsSuccess = false;
                    resp.Message   = "Your session was expired, please re-login.";
                    return(resp);
                }
                string search   = HttpContext.Request.Query["search[value]"].ToString();
                int    draw     = Convert.ToInt32(HttpContext.Request.Query["draw"]);
                string order    = HttpContext.Request.Query["order[0][column]"];
                string orderDir = HttpContext.Request.Query["order[0][dir]"];
                int    startRec = Convert.ToInt32(HttpContext.Request.Query["start"]);
                int    pageSize = Convert.ToInt32(HttpContext.Request.Query["length"]);
                resp = await facade.GetAll(search, order, orderDir, startRec, pageSize, draw);


                return(resp);
            }
            catch (Exception)
            {
                return(resp);
            }
            //try
            //{

            //    if (models == null)
            //    {
            //        return NotFound();
            //    }

            //    return Ok(models);
            //}
            //catch (Exception ex)
            //{
            //    return BadRequest(ex);
            //}
        }
Exemple #6
0
        public async Task <DealerResponse> DeletePost(long ID)
        {
            DealerResponse resp = new DealerResponse();

            try
            {
                string bearer   = Request.HttpContext.Request.Headers["Authorization"];
                string token    = bearer.Substring("Bearer ".Length).Trim();
                string username = string.Empty;
                if (string.IsNullOrEmpty(token))
                {
                    resp.IsSuccess = false;
                    resp.Message   = "You don't have access.";
                    return(resp);
                }

                username = sec.ValidateToken(token);
                if (username == null)
                {
                    Response.HttpContext.Response.Cookies.Append("access_token", "", new CookieOptions()
                    {
                        Expires = DateTime.Now.AddDays(-1)
                    });
                    resp.IsSuccess = false;
                    resp.Message   = "Your session was expired, please re-login.";
                    return(resp);
                }

                resp = await facade.DeletePost(ID, username);


                return(resp);
            }
            catch (Exception)
            {
                return(resp);
            }
            //DealerResponse response = new DealerResponse();


            //try
            //{
            //    if (ID < 1)
            //    {
            //        return BadRequest();
            //    }

            //    response = await facade.DeletePost(ID);

            //    return Ok(response);
            //}
            //catch (Exception)
            //{

            //    return BadRequest();
            //}
        }
        private async void BuyIcon_Tapped(object sender, EventArgs e)
        {
            if (credit.Interest != null && credit.Duration != null && credit.Cost != null)
            {
                if (credit.IsAffordable())
                {
                    AppSettings setting = (await App.LocalDataBase.GetAppSettings())[0];
                    await App.LocalDataBase.ChangeAppTime(DateTime.Parse(setting.LastRealLogin));
                    setting = (await App.LocalDataBase.GetAppSettings())[0];
                    var creditListView = new CreditListView();
                    creditListView.BindingContext = credit;
                    StationaryCredit stationaryCredit = new StationaryCredit();
                    stationaryCredit.Interest = (double)credit.Interest;
                    stationaryCredit.Duration = (double)credit.Duration;
                    stationaryCredit.Cost = (double)credit.Cost;
                    stationaryCredit.DateBought = DateTime.Parse(setting.LastRealLogin);
                    stationaryCredit.MonthsRemaining = (double)credit.Duration;
                    stationaryCredit.LatestPayment = DateTime.Parse(setting.LastLogin);
                    stationaryCredit.AppDateBought = DateTime.Parse(setting.LastLogin);
                    DealerResponse response = await App.LocalDataBase.AddCredit(stationaryCredit);
                    List<StationaryCredit> credits = await App.LocalDataBase.GetCredits();
                    if (response == DealerResponse.Success)
                    {
                        //await DisplayAlert("", "Operation Successful", "OK");
                        await Navigation.PushAsync(new MainView());
                    }
                    else
                    {
                        await DisplayAlert("", "Something went wrong, we're sorry", "OK");
                    }


                }
                else
                {
                    await DisplayAlert("", "You cannot afford the credit", "OK");
                }
            }
            else
            {
                await DisplayAlert("", "Please fill in all the fields", "OK");
            }
        }
Exemple #8
0
        public async Task <DealerResponse> SellAuctionBundle(AuctionBundle auctionBundle)
        {
            DealerResponse response = new DealerResponse();
            List <object>  payload  = new List <object>();

            payload.Add(auctionBundle);
            AuctionBundleForDb bundleForSymbol = await GetAuctionBundleForSymbol(auctionBundle.Symbol, App.User);

            if (bundleForSymbol != null)
            {
                payload.Add(bundleForSymbol);
                response = App.MiddleDealer.OnEvent(Databases.MessageAction.SellAuctionBundle, payload);
            }
            else
            {
                return(DealerResponse.NoAuctionsFromCompany);
            }

            return(response);
        }
Exemple #9
0
        public async Task <DealerResponse> ChangeAppTime(DateTime lastTime)
        {
            DealerResponse     response = new DealerResponse();
            List <AppSettings> s        = await GetAppSettings();

            AppSettings setting     = s[0];
            DateTime    currentTime = DateTime.Now;
            TimeSpan    span        = currentTime.Subtract(lastTime);
            double      minutespan  = span.TotalMinutes;

            minutespan *= App.Multiplier;
            DateTime t = DateTime.Parse(setting.LastLogin).AddMinutes(minutespan);

            setting.LastRealLogin = DateTime.Now.ToString();
            setting.LastLogin     = t.ToString();
            await SaveAppSetting(setting);

            response = DealerResponse.Success;
            return(response);
        }
Exemple #10
0
        public async Task <DealerResponse> AddPost(DealerRequest request)
        {
            DealerResponse response = new DealerResponse();

            try
            {
                Dealer model = new Dealer();
                model.Name          = request.Name;
                model.Kode          = request.Kode;
                model.Alamat        = request.Alamat;
                model.KotaId        = request.KotaID;
                model.Telepon       = request.Telepon;
                model.PejabatDealer = request.PejabatDealer;
                model.Created       = DateTime.Now;
                model.CreatedBy     = request.UserName;
                model.RowStatus     = true;

                long result = 0;
                result = await dep.AddPost(model);

                if (result > 0)
                {
                    response.Message   = "success";
                    response.IsSuccess = true;
                }
                else
                {
                    response.Message   = "failed";
                    response.IsSuccess = false;
                }
            }
            catch (Exception ex)
            {
                log.Error(ex);
                response.Message   = ex.ToString();
                response.IsSuccess = false;
            }
            return(response);
        }
Exemple #11
0
        public async Task <IActionResult> GetAllForDropdown(int KotaID)
        {
            DealerResponse response = new DealerResponse();

            try
            {
                response.ListDealer = await facade.GetAllForDropdown(KotaID);

                response.IsSuccess = true;
                response.Message   = "Success";

                if (response == null)
                {
                    return(NotFound());
                }

                return(Ok(response));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex));
            }
        }
Exemple #12
0
        private async void MeddleWithDB()
        {
            /// de trimis request la middledealer sa verifica income-urile cand porneste aplicatia



            Person             person   = App.User;
            List <AppSettings> settings = await App.LocalDataBase.GetAppSettings();

            if (settings.Count == 0)
            {
                AppSettings currentSetting = new AppSettings();
                currentSetting.CurrentPerson = person.Id;
                DateTime currentTime = DateTime.Now.ToLocalTime();
                currentSetting.FirstLogin    = currentTime.ToString();
                currentSetting.LastRealLogin = currentTime.ToString();
                currentSetting.LastLogin     = currentTime.ToString();
                int awaiter = await App.LocalDataBase.AddAppSetting(currentSetting);
            }
            else
            {
                AppSettings    setting       = settings[settings.Count - 1] as AppSettings;
                DateTime       timeLastLogin = DateTime.Parse(setting.LastRealLogin);
                DealerResponse response      = await App.LocalDataBase.ChangeAppTime(timeLastLogin);

                setting = (await App.LocalDataBase.GetAppSettings())[0];

                List <Income> incomes = await App.LocalDataBase.GetIncomes();

                if (incomes.Count > 0)
                {
                    List <object> payload = new List <object>();
                    foreach (Income i in incomes)
                    {
                        payload.Add(i);
                    }
                    await App.LocalDataBase.ManageIncomes(payload);
                }
                List <AppSettings> s = await App.LocalDataBase.GetAppSettings();

                incomes = await App.LocalDataBase.GetIncomes();

                if (response == DealerResponse.Success)
                {
                    //await DisplayAlert("", "Successfyully updated time!" + s[0].LastLogin.ToString(), "OK");
                }

                DateTime currentTime   = DateTime.Now.ToLocalTime();
                double   currentAmount = CalculateMoneyToEarn(Convert.ToDateTime(setting.LastRealLogin), person);

                if (currentAmount != person.Amount)
                {
                    person.Amount = currentAmount;

                    int awaiter = await App.LocalDataBase.SavePerson(person);

                    binding.MoneyStatement = person.Amount;
                }
                binding.MoneyStatement = person.Amount;
                //await CalculateMoneyToGive(person, this);
            }

            binding.MoneyStatement = person.Amount;
            settings = await App.LocalDataBase.GetAppSettings();

            PersonToAuctionBundleConnection        conn  = new PersonToAuctionBundleConnection();
            List <PersonToAuctionBundleConnection> conns = await App.LocalDataBase.GetPersonToAuctionBundleConncetions();

            List <AuctionBundleForHistory> bundles = await App.LocalDataBase.GetHistory();

            List <StationaryCredit> credits = await App.LocalDataBase.GetCredits();

            Currency curr = await App.LocalDataBase.GetCurrency(person.CurrencyID);

            if (bundles.Count != 0)
            {
                //HistoryButton.IsEnabled = true;
            }
            if (credits.Count != 0)
            {
                //CreditListButton.IsEnabled = true;
            }
        }
Exemple #13
0
        public async Task <DealerResponse> GetAll(string search, string order, string orderDir, int startRec, int pageSize, int draw)
        {
            DealerResponse response = new DealerResponse();

            if (db != null)
            {
                try
                {
                    var query = (from dealer in db.Dealer
                                 join kota in db.Kota
                                 on dealer.KotaId equals kota.Id
                                 where dealer.RowStatus == true && kota.RowStatus == true
                                 select new
                    {
                        dealer.Id,
                        dealer.Name,
                        dealer.Kode,
                        dealer.Alamat,
                        KotaID = kota.Id,
                        KotaName = kota.Name,
                        dealer.Telepon,
                        dealer.PejabatDealer,
                    });

                    int totalRecords = query.Count();
                    if (!string.IsNullOrEmpty(search) && !string.IsNullOrWhiteSpace(search))
                    {
                        query = query.Where(p => p.Name.ToString().ToLower().Contains(search.ToLower()) ||
                                            p.Kode.ToString().ToLower().Contains(search.ToLower()) ||
                                            p.Alamat.ToString().ToLower().Contains(search.ToLower()) ||
                                            p.KotaName.ToString().ToLower().Contains(search.ToLower()) ||
                                            p.PejabatDealer.ToLower().Contains(search.ToLower()));
                    }

                    int recFilter = query.Count();
                    response.ListModel = await(from model in query
                                               select new DealerViewModel
                    {
                        ID            = model.Id,
                        Name          = model.Name,
                        Kode          = model.Kode,
                        Alamat        = model.Alamat,
                        KotaID        = model.KotaID,
                        KotaName      = model.KotaName,
                        Telepon       = model.Telepon,
                        PejabatDealer = model.PejabatDealer
                    }).Skip(startRec).Take(pageSize).ToListAsync();
                    response.draw            = Convert.ToInt32(draw);
                    response.recordsTotal    = totalRecords;
                    response.recordsFiltered = recFilter;
                    response.Message         = "Load Success";
                    response.IsSuccess       = true;
                }
                catch (Exception ex)
                {
                    response.Message   = ex.ToString();
                    response.IsSuccess = false;
                }
            }
            return(response);
        }
Exemple #14
0
        public DealerResponse OnMessageReceived(MessageAction message, List <object> payload)
        {
            Person         person   = App.User;
            DealerResponse response = DealerResponse.Unreachable;

            switch (message)
            {
            case MessageAction.AddedAuctionBundle:
            {
                person = App.User;

                var    auctionBundle = payload[0] as AuctionBundle;
                double numberToBuy   = double.Parse(auctionBundle.Number, System.Globalization.CultureInfo.InvariantCulture);
                if (payload.Count == 1)
                {
                    double auxNumber   = double.Parse(auctionBundle.Number, System.Globalization.CultureInfo.InvariantCulture);
                    double amountToPay = auctionBundle.CloseValueAtDateBought * auxNumber;
                    person.Amount -= amountToPay;

                    AuctionBundleForHistory bundle = new AuctionBundleForHistory(auctionBundle.Symbol, auctionBundle.Name, auctionBundle.OpenValueAtDateBought, auctionBundle.CloseValueAtDateBought, auctionBundle.DateBought, auctionBundle.Number, AuctionAction.BOUGHT);;
                    bundle.PersonID = person.Id;
                    App.LocalDataBase.AddAuctionBundleToHistory(bundle);
                    App.LocalDataBase.SavePerson(person);
                    response = DealerResponse.Success;
                }
                else
                {
                    AuctionBundleForDb bundleForSymbol = payload[1] as AuctionBundleForDb;
                    bundleForSymbol.MedianValue = ((bundleForSymbol.MedianValue * bundleForSymbol.Number) + (numberToBuy * auctionBundle.CloseValueAtDateBought)) / (double.Parse(auctionBundle.Number, System.Globalization.CultureInfo.InvariantCulture) + bundleForSymbol.Number);
                    bundleForSymbol.Number     += double.Parse(auctionBundle.Number, System.Globalization.CultureInfo.InvariantCulture);
                    AuctionBundleForHistory bundle = new AuctionBundleForHistory(auctionBundle.Symbol, auctionBundle.Name, auctionBundle.OpenValueAtDateBought, auctionBundle.CloseValueAtDateBought, auctionBundle.DateBought, auctionBundle.Number, AuctionAction.BOUGHT);;
                    bundle.PersonID = person.Id;
                    person.Amount  -= numberToBuy * auctionBundle.CloseValueAtDateBought;
                    App.LocalDataBase.SavePerson(person);
                    App.LocalDataBase.AddAuctionBundleToHistory(bundle);
                    SaveAuctionBundle(bundleForSymbol);
                    response = DealerResponse.Success;
                }
                break;
            }

            case MessageAction.GetAllDepositedMoney:
            {
                person = App.User;
                List <Income> incomes = new List <Income>();
                foreach (object o in payload)
                {
                    incomes.Add((Income)o);
                }
                foreach (Income i in incomes)
                {
                    person.Amount += i.AbsoluteValue + i.OverTimeAddition;
                    DeleteIncome(i);
                }

                return(DealerResponse.Success);

                break;
            }

            case MessageAction.ManageIncomes:
            {
                List <Income> incomes = new List <Income>();
                for (int i = 0; i < payload.Count - 1; i++)
                {
                    incomes.Add((Income)payload[i]);
                }
                AppSettings setting = payload[payload.Count - 1] as AppSettings;
                foreach (Income i in incomes)
                {
                    if (i.Times != -1)
                    {
                        if (i.TimesLeft > 0 && i.LastRealPayment != null)
                        {
                            DateTime lastRealLogin = DateTime.Parse(setting.LastRealLogin);
                            TimeSpan span          = lastRealLogin.Subtract(DateTime.Parse(i.LastRealSupposedPayment));
                            double   appMinutes    = span.TotalMinutes * App.Multiplier;

                            if (appMinutes > i.Frequency)
                            {
                                // se sustrage/se adauga la persoana cat trebuie sa plateasca


                                double timesToSubtract = appMinutes / i.Frequency;
                                timesToSubtract           = Math.Floor(timesToSubtract);
                                i.TimesLeft              -= int.Parse(Math.Floor(timesToSubtract).ToString());
                                i.LastSupposedPayment     = (DateTime.Parse(i.LastSupposedPayment).AddMinutes(timesToSubtract * i.Frequency)).ToString();
                                i.LastRealSupposedPayment = (DateTime.Parse(i.LastRealSupposedPayment).AddMinutes((timesToSubtract * i.Frequency) / App.Multiplier)).ToString();
                                i.LastAppPayment          = setting.LastLogin;
                                i.LastRealPayment         = setting.LastRealLogin;
                                SaveIncome(i);
                                person.Amount += (i.AbsoluteValue * timesToSubtract);
                                SavePerson(person);
                            }
                        }
                    }
                    else
                    {
                        switch (i.Category)
                        {
                        case IncomeCategory.DefaultDeposit:
                        {
                            DateTime lastRealLogin = DateTime.Parse(setting.LastRealLogin);
                            TimeSpan span          = lastRealLogin.Subtract(DateTime.Parse(i.LastRealSupposedPayment));
                            double   appMinutes    = span.TotalMinutes * App.Multiplier;
                            if (appMinutes > i.Frequency)
                            {
                                double timesToSubtract = appMinutes / i.Frequency;
                                timesToSubtract           = Math.Floor(timesToSubtract);
                                i.OverTimeAddition       += Math.Floor(timesToSubtract) * ((i.DepositInterest / 100) * i.AbsoluteValue);
                                i.LastSupposedPayment     = (DateTime.Parse(i.LastSupposedPayment).AddMinutes(timesToSubtract * i.Frequency)).ToString();
                                i.LastRealSupposedPayment = (DateTime.Parse(i.LastRealSupposedPayment).AddMinutes((timesToSubtract * i.Frequency) / App.Multiplier)).ToString();
                                i.LastAppPayment          = setting.LastLogin;
                                i.LastRealPayment         = setting.LastRealLogin;
                                SaveIncome(i);
                            }
                            break;
                        }

                        case IncomeCategory.Job:
                        {
                            DateTime lastRealLogin = DateTime.Parse(setting.LastRealLogin);
                            TimeSpan span          = lastRealLogin.Subtract(DateTime.Parse(i.LastRealSupposedPayment));
                            double   appMinutes    = span.TotalMinutes * App.Multiplier;
                            if (appMinutes > i.Frequency)
                            {
                                double timesToSubtract = appMinutes / i.Frequency;
                                timesToSubtract = Math.Floor(timesToSubtract);
                                // se adauga la person banii
                                i.LastSupposedPayment     = (DateTime.Parse(i.LastSupposedPayment).AddMinutes(timesToSubtract * i.Frequency)).ToString();
                                i.LastRealSupposedPayment = (DateTime.Parse(i.LastRealSupposedPayment).AddMinutes((timesToSubtract * i.Frequency) / App.Multiplier)).ToString();
                                i.LastAppPayment          = setting.LastLogin;
                                i.LastRealPayment         = setting.LastRealLogin;
                                person.Amount            += i.AbsoluteValue * timesToSubtract;
                                SavePerson(person);
                                SaveIncome(i);
                            }
                            break;
                        }
                        }
                    }
                }

                return(DealerResponse.Success);

                break;
            }

            case MessageAction.BuyCredit: {
                StationaryCredit credit = payload[0] as StationaryCredit;
                Income           income = new Income();
                income.Category      = IncomeCategory.Credit;
                income.AbsoluteValue = (-1) * (((credit.Cost * (100 + credit.Interest)) / 100) / credit.Duration);
                income.Periodical    = true;
                income.Frequency     = 30;
                // contracttime, lastpayment, lastrealpayment, lastsupppayment, lastrealsupppayment
                income.Times                   = (int)credit.Duration;
                income.TimesLeft               = (int)(income.Times);
                income.ContractTime            = credit.DateBought.ToString();
                income.LastRealPayment         = credit.DateBought.ToString();
                income.LastAppPayment          = credit.AppDateBought.ToString();
                income.LastRealSupposedPayment = credit.DateBought.ToString();
                income.LastSupposedPayment     = credit.AppDateBought.ToString();
                AddIncome(income);
                response = DealerResponse.Success;
                break;
            }

            case MessageAction.SellAuctionBundle:
            {
                AuctionBundle      auctionBundle   = payload[0] as AuctionBundle;
                AuctionBundleForDb bundleForSymbol = payload[1] as AuctionBundleForDb;
                double             numberToSell    = double.Parse(auctionBundle.Number, System.Globalization.CultureInfo.InvariantCulture);
                if ((bundleForSymbol.Number - numberToSell) >= 0)
                {
                    bundleForSymbol.Number -= numberToSell;
                    App.LocalDataBase.SaveAuctionBundle(bundleForSymbol);
                    person.Amount += numberToSell * auctionBundle.CloseValueAtDateBought;
                    AuctionBundleForHistory bundle = new AuctionBundleForHistory(auctionBundle.Symbol, auctionBundle.Name, auctionBundle.OpenValueAtDateBought, auctionBundle.CloseValueAtDateBought, auctionBundle.DateBought, auctionBundle.Number, AuctionAction.SOLD);;
                    bundle.PersonID = person.Id;
                    App.LocalDataBase.AddAuctionBundleToHistory(bundle);
                    App.LocalDataBase.SavePerson(person);
                    App.LocalDataBase.SaveAuctionBundle(bundleForSymbol);
                    response = DealerResponse.Success;
                }
                else
                {
                    return(DealerResponse.NotEnoughAuctions);
                }


                break;
            }
            }

            return(response);
        }
Exemple #15
0
        public async Task <DealerResponse> AddPost([FromBody] DealerRequest model)
        {
            DealerResponse resp = new DealerResponse();

            try
            {
                string bearer   = Request.HttpContext.Request.Headers["Authorization"];
                string token    = bearer.Substring("Bearer ".Length).Trim();
                string username = string.Empty;
                if (string.IsNullOrEmpty(token))
                {
                    resp.IsSuccess = false;
                    resp.Message   = "You don't have access.";
                    return(resp);
                }

                username = sec.ValidateToken(token);
                if (username == null)
                {
                    Response.HttpContext.Response.Cookies.Append("access_token", "", new CookieOptions()
                    {
                        Expires = DateTime.Now.AddDays(-1)
                    });
                    resp.IsSuccess = false;
                    resp.Message   = "Your session was expired, please re-login.";
                    return(resp);
                }
                model.UserName = username;
                if (model.ID > 0)
                {
                    resp = await facade.UpdatePost(model);
                }
                else
                {
                    resp = await facade.AddPost(model);
                }


                return(resp);
            }
            catch (Exception)
            {
                return(resp);
            }

            //DealerResponse result = new DealerResponse();
            //if (ModelState.IsValid)
            //{
            //    try
            //    {
            //        if (model.ID > 0)
            //        {
            //            result = await facade.UpdatePost(model);
            //        }
            //        else
            //        {
            //            result = await facade.AddPost(model);
            //        }
            //        return Ok(result);
            //    }
            //    catch (Exception)
            //    {
            //        return BadRequest();
            //    }
            //}
            //return BadRequest();
        }
        private async void AddBundleToStockPortfolio(AuctionBundle auctionBundle)
        {
            Person person = App.User;

            string numberToBuy = auctionBundle.Number;

            if (action == AuctionAction.BOUGHT)
            {
                string auctionNumber    = auctionBundle.Number;
                double auxAuctionNumber = double.Parse(auctionNumber);
                if (person.Amount < (auctionBundle.CloseValueAtDateBought * auxAuctionNumber))
                {
                    await DisplayAlert("", "You do not have enough money", "OK");
                }
                else
                {
                    auctionBundle.PersonID = person.Id;
                    DealerResponse response = await App.LocalDataBase.AddAuctionBundle(auctionBundle);

                    if (response == DealerResponse.Success)
                    {
                        await DisplayAlert("", "Congratulations, you have just bought " + auctionNumber + " auctions", "OK");

                        await Navigation.PushAsync(new AuctionHouseView());
                    }
                }
            }
            else
            {
                AuctionBundleForDb boughtBundle = await App.LocalDataBase.GetAuctionBundleForSymbol(auctionBundle.Symbol, person);

                if (boughtBundle == null)
                {
                    await DisplayAlert("", "You have not bought auctions from this company yet", "OK");
                }
                else
                {
                    double profit = (auctionBundle.OpenValueAtDateBought - boughtBundle.MedianValue) * double.Parse(auctionBundle.Number, System.Globalization.CultureInfo.InvariantCulture);

                    ProfitLabel.Text      = "You gain " + profit + " from transactioning " + auctionBundle.Number + " auctions from " + auctionBundle.Name;
                    ProfitLabel.IsVisible = true;
                    DealerResponse response = await App.LocalDataBase.SellAuctionBundle(auctionBundle);

                    switch (response)
                    {
                    case DealerResponse.Success:
                    {
                        await DisplayAlert("", "Congratuations, you have just sold " + auctionBundle.Number, "OK");

                        //await Navigation.PushAsync(new AuctionHouseView());
                        break;
                    }

                    case DealerResponse.NoAuctions:
                    {
                        await DisplayAlert("", "You have no auctions", "OK");

                        break;
                    }

                    case DealerResponse.NoAuctionsFromCompany:
                    {
                        await DisplayAlert("", "You have not bought auctions froms this company yet or have sold them all", "OK");

                        break;
                    }

                    case DealerResponse.NotEnoughAuctions:
                    {
                        await DisplayAlert("", "You do not have enough auctions", "OK");

                        break;
                    }
                    }
                }
            }
        }