Ejemplo n.º 1
0
        public ActionResult BuyItem(int id)
        {
            ActionResult actionResult = new ActionResult();

            try
            {
                Item foundItem = Market.Items[id];
                if (Customer.Money >= foundItem.price)
                {
                    Market.Items.Remove(foundItem);
                    Market.Income      += foundItem.price;
                    foundItem.addedDate = DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString();
                    Customer.MyBagItems.Add(foundItem);
                    Customer.Money     -= foundItem.price;
                    actionResult.Result = $"You have bought {foundItem.description} with {foundItem.price} AMD";
                }
                else
                {
                    actionResult.Result = $"You can't buy {foundItem.description} with {foundItem.price} AMD, because you have {Customer.Money} AMD";
                }
                actionResult.ResultCode        = ResultCodes.Normal;
                actionResult.ResultDescription = "Normal";
            }
            catch (Exception ex)
            {
                actionResult.Result            = null;
                actionResult.ResultCode        = ResultCodes.Error;
                actionResult.ResultDescription = ex.Message;
            }
            return(actionResult);
        }
Ejemplo n.º 2
0
        public ActionResult EditItem(Item item)
        {
            ActionResult actionResult = new ActionResult();

            try
            {
                if (Market.Items.Contains(item))
                {
                    Item itemForEdit = Market.Items.FirstOrDefault(foundItem => foundItem.description == item.description);
                    itemForEdit.description = item.description;
                    itemForEdit.price       = item.price;
                    itemForEdit.addedDate   = DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString();
                    actionResult.Result     = $"{item.description} edited";
                }
                else
                {
                    actionResult.Result = $"{item.description} not found";
                }
                actionResult.ResultCode        = ResultCodes.Normal;
                actionResult.ResultDescription = "Normal";
            }
            catch (Exception ex)
            {
                actionResult.Result            = null;
                actionResult.ResultCode        = ResultCodes.Error;
                actionResult.ResultDescription = ex.Message;
            }
            return(actionResult);
        }
Ejemplo n.º 3
0
        public ActionResult GetMyBagItems()
        {
            ActionResult actionResult = new ActionResult();

            try
            {
                if (Customer.MyBagItems.Count == 0)
                {
                    actionResult.Result = "My bag is empty";
                }
                else
                {
                    actionResult.Result = Customer.MyBagItems;
                }
                actionResult.ResultCode        = ResultCodes.Normal;
                actionResult.ResultDescription = "Normal";
            }
            catch (Exception ex)
            {
                actionResult.Result            = null;
                actionResult.ResultCode        = ResultCodes.Error;
                actionResult.ResultDescription = ex.Message;
            }
            return(actionResult);
        }
Ejemplo n.º 4
0
        public ActionResult GetStock()
        {
            ActionResult actionResult = new ActionResult();

            try
            {
                if (Market.Items.Count == 0)
                {
                    actionResult.Result = "Stock is empty";
                }
                else
                {
                    actionResult.Result = Market.Items;
                }
                actionResult.ResultCode        = ResultCodes.Normal;
                actionResult.ResultDescription = "Normal";
            }
            catch (Exception ex)
            {
                actionResult.Result            = null;
                actionResult.ResultCode        = ResultCodes.Error;
                actionResult.ResultDescription = ex.Message;
            }
            return(actionResult);
        }
Ejemplo n.º 5
0
        public ActionResult GetIncome()
        {
            ActionResult actionResult = new ActionResult();

            try
            {
                if (Market.Income == 0)
                {
                    actionResult.Result = "You haven't income";
                }
                else
                {
                    actionResult.Result = Market.Income;
                }
                actionResult.ResultCode        = ResultCodes.Normal;
                actionResult.ResultDescription = "Normal";
            }
            catch (Exception ex)
            {
                actionResult.Result            = null;
                actionResult.ResultCode        = ResultCodes.Error;
                actionResult.ResultDescription = ex.Message;
            }
            return(actionResult);
        }
Ejemplo n.º 6
0
        public ActionResult AddItem(Item item)
        {
            ActionResult actionResult = new ActionResult();

            try
            {
                Market.Items.Add(item);
                actionResult.Result            = $"{item.description} added";
                actionResult.ResultCode        = ResultCodes.Normal;
                actionResult.ResultDescription = "Normal";
            }
            catch (Exception ex)
            {
                actionResult.Result            = null;
                actionResult.ResultCode        = ResultCodes.Error;
                actionResult.ResultDescription = ex.Message;
            }
            return(actionResult);
        }
Ejemplo n.º 7
0
        public ActionResult AddEmployeer(Employeer employeer)
        {
            ActionResult actionResult = new ActionResult();

            try
            {
                Market.Employeers.Add(employeer);
                actionResult.Result            = $"{employeer.name + " " + employeer.surname} added with {employeer.salary} salary";
                actionResult.ResultCode        = ResultCodes.Normal;
                actionResult.ResultDescription = "Normal";
            }
            catch (Exception ex)
            {
                actionResult.Result            = null;
                actionResult.ResultCode        = ResultCodes.Error;
                actionResult.ResultDescription = ex.Message;
            }
            return(actionResult);
        }
Ejemplo n.º 8
0
        public ActionResult RemoveItem(int id)
        {
            ActionResult actionResult = new ActionResult();

            try
            {
                Item foundItem = Market.Items[id];
                Market.Items.Remove(foundItem);

                actionResult.Result            = $"{foundItem.description} removed.";
                actionResult.ResultCode        = ResultCodes.Normal;
                actionResult.ResultDescription = "Normal";
            }
            catch (Exception ex)
            {
                actionResult.Result            = "Item not found";
                actionResult.ResultCode        = ResultCodes.Error;
                actionResult.ResultDescription = ex.Message;
            }
            return(actionResult);
        }