Ejemplo n.º 1
0
        public bool Add(BuildingDto building)
        {
            if (!_buildings.GetAll().Any(i => i.Name == building.Name && i.Alias == building.Alias))
            {
                try
                {
                    _buildings.Add(new Buildings
                    {
                        Name = building.Name,
                        Price = building.Price,
                        Height = building.Height,
                        Width = building.Width,
                        Dest_price = building.Dest_price,
                        Percent_price_per_lvl = building.Percent_price_per_lvl,
                        Percent_product_per_lvl = building.Percent_product_per_lvl,
                        Product_ID = _products.GetAll().First(i => i.Alias == building.Product_Name).ID,
                        Product_per_sec = building.Product_per_sec,
                        Alias = building.Alias,
                        BuildingTime = building.BuildingTime,
                        DestructionTime = building.DestructionTime,
                        Stock = building.Stock
                    });

                    _unitOfWork.Commit();
                    return true;
                }
                catch (Exception)
                {
                    return false;
                }
            }
            return false;
        }
Ejemplo n.º 2
0
        public bool Update(BuildingDto building)
        {
            if (_buildings.GetAll().Any(i => i.ID == building.ID))
            {
                try
                {
                    foreach (var item in _buildings.GetAll().Where(i => i.ID == building.ID))
                    {
                        item.Name = building.Name;
                        item.Price = building.Price;
                        item.Percent_price_per_lvl = building.Percent_price_per_lvl;
                        item.Width = building.Width;
                        item.Height = building.Height;
                        item.Product_per_sec = building.Product_per_sec;
                        item.Dest_price = building.Dest_price;
                        item.Percent_product_per_lvl = building.Percent_product_per_lvl;
                        item.Product_ID = _products.GetAll().First(i => i.Alias == building.Product_Name).ID;
                        item.Alias = building.Alias;
                        item.BuildingTime = building.BuildingTime;
                        item.DestructionTime = building.DestructionTime;
                        item.Stock = building.Stock;
                    }
                    _unitOfWork.Commit();

                    return true;
                }
                catch (Exception ex)
                {
                }
            }
            return false;
        }
Ejemplo n.º 3
0
        public ActionResult AddBuilding(BuildingViewModel buildingModel)
        {
            List<string> errors;
            if (Session["val"] != null)
            {
                errors = ((string[])Session["val"]).ToList();
            }
            else
            {
                errors = new List<string>();
            }

            BuildingDto _buildingDto = new BuildingDto();

            _buildingDto.Name = buildingModel.viewModel.BuildingName;
            _buildingDto.Price = buildingModel.viewModel.Price;
            _buildingDto.Height = buildingModel.viewModel.Height;
            _buildingDto.Width = buildingModel.viewModel.Width;
            _buildingDto.Dest_price = (int)buildingModel.viewModel.DestructionTime;
            _buildingDto.Percent_price_per_lvl = buildingModel.viewModel.Percent_price_per_lvl;
            _buildingDto.Percent_product_per_lvl = buildingModel.viewModel.Percent_product_per_lvl;
            _buildingDto.Product_Name = buildingModel.viewModel.Product_Name;
            _buildingDto.Product_per_sec = buildingModel.viewModel.Product_per_sec;
            _buildingDto.Alias = buildingModel.viewModel.Alias;
            _buildingDto.BuildingTime = buildingModel.viewModel.BuildingTime;
            _buildingDto.DestructionTime = buildingModel.viewModel.DestructionTime;
            _buildingDto.Stock = buildingModel.viewModel.Stock.ToLower().Contains("tak") ? true : false;

            if (_buildingService.Add(_buildingDto))
            {
                errors.Add("Dodano budynek.");
            }
            else
            {
                errors.Add("Błąd. Spróbuj ponownie.");
            }
            Session["val"] = errors.ToArray<string>();

            return RedirectToAction("Admin");
        }