Beispiel #1
0
        public ActionResult AddDeal(DealViewModel dealModel)
        {
            List<string> errors;
            if (Session["val"] != null)
            {
                errors = ((string[])Session["val"]).ToList();
            }
            else
            {
                errors = new List<string>();
            }

            DealDto dealDto = new DealDto();

            dealDto.User1_Login = User.Identity.Name;
            dealDto.User2_Login = dealModel.viewModel.User2_Login;
            dealDto.Building_Name = dealModel.viewModel.Building_Name;
            if (dealModel.viewModel.Owner == true)
            {
                dealDto.Map_ID = 1;
            }
            else
            {
                dealDto.Map_ID = 0;
            }
            var temp = dealModel.viewModel.Value;
            dealDto.Percent_User1 = dealModel.viewModel.Percent_User1;
            dealDto.FinishDate = (DateTime.Now.AddDays(dealModel.viewModel.DealDay));
            dealDto.DayTime = dealModel.viewModel.DealDay;

            if (dealDto.User2_Login != User.Identity.Name)
            {
                foreach (var item in _dealService.AddDeal(dealDto))
                {
                    if (item == 1)
                    {
                        NotificationDto notificationDto = new NotificationDto();

                        notificationDto.Description = "Nowa umowa";
                        notificationDto.User_Login = dealModel.viewModel.User2_Login;

                        _notificationService.SentNotification(notificationDto);

                        errors.Add("Oferta złożona");
                    }
                    else if (item == 2)
                    {
                        errors.Add("Taki budyenk nie istnieje.");
                    }
                    else if (item == 0)
                    {
                        errors.Add("Taki użytkownik nie istnieje.");
                    }
                    else if (item == 3)
                    {
                        errors.Add("Nie stać Cię na taką umowę.");
                    }
                }
            }
            else if (dealDto.User2_Login == User.Identity.Name)
            {
                errors.Add("Nie możesz złożyć oferty samemu sobie");
            }

            Session["val"] = errors.ToArray<string>();
            return RedirectToAction("Index");
        }
Beispiel #2
0
        public int[] AddDeal(DealDto dealDto)
        {
            List<int> val = new List<int>();

            if (_users.GetAll().Any(i => i.Login == dealDto.User2_Login))
            {
                if (_buildings.GetAll().Any(i => i.Alias == dealDto.Building_Name))
                {
                    int user1ID = _users.GetAll().First(i => i.Login == dealDto.User1_Login).ID;
                    int user2ID = _users.GetAll().First(i => i.Login == dealDto.User2_Login).ID;
                    int buildingID = _buildings.GetAll().First(i => i.Alias == dealDto.Building_Name).ID;
                    int mapID = 0;
                    if (dealDto.Map_ID == 1)
                    {
                        mapID = _maps.GetAll().First(i => i.User_ID == user1ID).Map_ID;
                    }
                    else if (dealDto.Map_ID == 0)
                    {
                        mapID = _maps.GetAll().First(i => i.User_ID == user2ID).Map_ID;
                    }

                    if (dealDto.Percent_User1 >= 10 && dealDto.Percent_User1 <= 90)
                    {
                        double tempPrice = (double)_buildings.Get(buildingID).Price * ((double)dealDto.Percent_User1 / 100.0);
                        int tempDolar = _dolars.GetAll().First(i => i.User_ID == user1ID).Value;
                        if (tempDolar >= (int)tempPrice)
                        {
                            _deals.Add(new Deals
                            {
                                User1_ID = user1ID,
                                User2_ID = user2ID,
                                Building_ID = _buildings.GetAll().First(i => i.Alias == dealDto.Building_Name).ID,
                                Map_ID = mapID,
                                IsActive = false,
                                Percent_User1 = dealDto.Percent_User1,
                                Percent_User2 = 100 - dealDto.Percent_User1,
                                FinishDate = (DateTime)dealDto.FinishDate,
                                DayTime = dealDto.DayTime
                            });

                            _unitOfWork.Commit();
                            int price = ((_buildings.Get(buildingID).Price * dealDto.Percent_User1) / 100);
                            int dolar = _dolars.GetAll().First(i => i.User_ID == user1ID).Value;

                            _dolars.GetAll().First(i => i.User_ID == user1ID).Value -= price;
                            _unitOfWork.Commit();

                            val.Add(1); //Oferta złożona
                        }
                        else
                        {
                            val.Add(3); //Brak funduszy
                        }
                    }
                }
                else
                {
                    val.Add(2); //Nie ma takiego budynku
                }
            }
            else
            {
                val.Add(0); //Nie ma takiego użytkownika
            }

            return val.ToArray();
        }
Beispiel #3
0
        public bool AddDealAdmin(DealDto dealDto)
        {
            if (_users.GetAll().Any(i => i.Login == dealDto.User1_Login)
                && (_users.GetAll().Any(i => i.Login == dealDto.User2_Login))
                && ((dealDto.Percent_User1 >= 10) && (dealDto.Percent_User1 <= 90))
                && ((100 - dealDto.Percent_User2) == dealDto.Percent_User1))
            {
                _deals.Add(new Deals
                {
                    Building_ID = _buildings.GetAll().First(i => i.Alias == dealDto.Building_Name).ID,
                    IsActive = dealDto.IsActive,
                    Percent_User1 = dealDto.Percent_User1,
                    Percent_User2 = dealDto.Percent_User2,
                    User1_ID = _users.GetAll().First(i => i.Login == dealDto.User1_Login).ID,
                    User2_ID = _users.GetAll().First(i => i.Login == dealDto.User2_Login).ID,
                    DayTime = dealDto.DayTime,
                    Map_ID = dealDto.OwnerLogin.ToLower().Contains(dealDto.User1_Login) ? _maps.GetAll().First(i => i.Users.Login == dealDto.User1_Login).Map_ID : _maps.GetAll().First(i => i.Users.Login == dealDto.User2_Login).Map_ID,
                    FinishDate = DateTime.Now.AddDays(dealDto.DayTime)
                });
                _unitOfWork.Commit();

                if (dealDto.IsActive)
                {
                    int uID1 = _users.GetAll().First(i => i.Login == dealDto.User1_Login).ID;
                    int uID2 = _users.GetAll().First(i => i.Login == dealDto.User2_Login).ID;
                    int buildingID = _buildings.GetAll().First(i => i.Alias == dealDto.Building_Name).ID;
                    _dealsBuildings.Add(new DealsBuildings
                    {
                        Deal_ID = _deals.GetAll().OrderByDescending(i=>i.ID).First(l => l.User1_ID == uID1 && l.User2_ID == uID2 && l.Building_ID == buildingID).ID,
                        User_ID = _users.GetAll().First(i => i.Login == dealDto.OwnerLogin).ID,
                        Building_ID = buildingID
                    });

                    _unitOfWork.Commit();
                }
                return true;
            }
            return false;
        }
Beispiel #4
0
        public bool UpdateDealAdmin(DealDto dealDto)
        {
            if (_users.GetAll().Any(i => i.Login == dealDto.User1_Login)
                && (_users.GetAll().Any(i => i.Login == dealDto.User2_Login))
                && ((dealDto.Percent_User1 >= 10) && (dealDto.Percent_User1 <= 90))
                && ((100 - dealDto.Percent_User2) == dealDto.Percent_User1))
            {
                foreach (var item in _deals.GetAll().Where(i => i.ID == dealDto.ID))
                {
                    int uID1 = _users.GetAll().First(i => i.Login == dealDto.User1_Login).ID;
                    int uID2 = _users.GetAll().First(i => i.Login == dealDto.User2_Login).ID;
                    item.IsActive = dealDto.IsActive;
                    item.Percent_User1 = dealDto.Percent_User1;
                    item.Percent_User2 = dealDto.Percent_User2;
                    item.User1_ID = uID1;
                    item.User2_ID = uID2;
                    item.FinishDate = DateTime.Now.AddDays(dealDto.DayTime);
                    item.DayTime = dealDto.DayTime;
                    item.Map_ID = dealDto.OwnerLogin.ToLower().Contains(dealDto.User1_Login) ? _maps.GetAll().First(i => i.User_ID == uID1).Map_ID : _maps.GetAll().First(i => i.User_ID == uID2).Map_ID;
                    item.Building_ID = _buildings.GetAll().First(i => i.Alias == dealDto.Building_Name).ID;
                }

                _unitOfWork.Commit();
                return true;
            }
            return false;
        }
Beispiel #5
0
        public ActionResult AddDeal(DealViewModel dealModel)
        {
            List<string> errors;
            if (Session["val"] != null)
            {
                errors = ((string[])Session["val"]).ToList();
            }
            else
            {
                errors = new List<string>();
            }

            DealDto dealDto = new DealDto();

            dealDto.Building_Name = dealModel.viewModel.Building_Name;
            dealDto.DayTime = dealModel.viewModel.DealDay;
            dealDto.IsActive = dealModel.viewModel.Active.ToLower().Contains("tak")? true : false;
            dealDto.OwnerLogin = dealModel.viewModel.OwnerLogin.ToLower().Contains("użytkownik 1") ? dealModel.viewModel.User1_Login : dealModel.viewModel.User2_Login;
            dealDto.Percent_User1 = dealModel.viewModel.Percent_User1;
            dealDto.Percent_User2 = dealModel.viewModel.Percent_User2;
            dealDto.User2_Login = dealModel.viewModel.User2_Login;
            dealDto.User1_Login = dealModel.viewModel.User1_Login;

            if(_dealService.AddDealAdmin(dealDto))
            {
                errors.Add("Dodano umowę.");
            }
            else
            {
                errors.Add("Błąd. Spróbuj ponownie.");
            }
            Session["val"] = errors.ToArray<string>();

            return RedirectToAction("Admin");
        }