public async Task Get_Item_By_Id_Should_Return_HttpOk()
        {
            //Arrange
            var item = new CatalogItem {
                AvailableStock = 1, Name = "name"
            };
            var id = 1;

            _repository.Setup(x => x.GetItemAsync(id)).Returns(Task.FromResult(item));

            //Act
            var actionResult = await _controller.GetById(id) as ObjectResult;

            //Assert
            Assert.NotNull(actionResult);
            Assert.Equal(actionResult.StatusCode, (int)HttpStatusCode.OK);
        }
Ejemplo n.º 2
0
        public override void HandleMessage(Yupi.Model.Domain.Habbo session, Yupi.Protocol.Buffers.ClientMessage message,
                                           Yupi.Protocol.IRouter router)
        {
            // TODO Maximum items

            int    pageId    = message.GetInteger();
            int    itemId    = message.GetInteger();
            string extraData = message.GetString();
            int    amount    = message.GetInteger();

            CatalogOffer item = CatalogController.GetById(pageId, itemId);

            CatalogController.Purchase(session, item, extraData, amount);
        }
        public override void HandleMessage(Yupi.Model.Domain.Habbo session, Yupi.Protocol.Buffers.ClientMessage message,
                                           Yupi.Protocol.IRouter router)
        {
            int    pageId       = message.GetInteger();
            int    itemId       = message.GetInteger();
            string extraData    = message.GetString();
            string giftUser     = message.GetString();
            string giftMessage  = message.GetString();
            int    giftSpriteId = message.GetInteger();
            int    giftLazo     = message.GetInteger();
            int    giftColor    = message.GetInteger();
            bool   showSender   = message.GetBool();

            UserInfo info = UserRepository.Find(x => x.Name == giftUser);

            if (info == null)
            {
                router.GetComposer <GiftErrorMessageComposer>().Compose(session, giftUser);
            }

            CatalogOffer item = CatalogController.GetById(pageId, itemId);

            CatalogController.PurchaseGift(session, item, extraData, info);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Insert or Update Catalog
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void InsertOrUpdate(object sender, DirectEventArgs e)
        {
            try
            {
                // init model
                var model = new CatalogModel(hdfObjName.Text)
                {
                    EditedBy = CurrentUser.User.UserName
                };

                // check id
                if (!string.IsNullOrEmpty(hdfId.Text) && Convert.ToInt32(hdfId.Text) > 0)
                {
                    var result = CatalogController.GetById(hdfObjName.Text, Convert.ToInt32(hdfId.Text));
                    if (result != null)
                    {
                        model = result;
                    }
                }

                // set new props for model
                model.Name        = txtName.Text;
                model.Description = txtDescription.Text;
                model.Order       = !string.IsNullOrEmpty(txtOrder.Text) ? Convert.ToInt32(txtOrder.Text) : 0;
                model.Group       = hdfGroup.Text;
                if (Enum.TryParse(hdfStatus.Text, false, out CatalogStatus status))
                {
                    model.Status = status;
                }

                // if cat group is record status
                if (hdfCatalogGroup.Text == nameof(RecordStatus).ToLower())
                {
                    if (Enum.TryParse(hdfGroup.Text, false, out RecordStatus group))
                    {
                        model.Group = ((int)group).ToString();
                    }
                }

                // create result model
                CatalogModel resultModel;

                // check model id
                if (model.Id > 0)
                {
                    // update
                    resultModel = CatalogController.Update(hdfObjName.Text, model);

                    // log action
                    SystemLogController.Create(new SystemLogModel(CurrentUser.User.UserName, "Danh mục {0}".FormatWith(hdfObjName.Text), SystemAction.Edit,
                                                                  "Sửa danh mục {0}".FormatWith(model.Name)));
                }
                else
                {
                    // set created user
                    model.CreatedBy = CurrentUser.User.UserName;

                    // insert
                    resultModel = CatalogController.Create(hdfObjName.Text, model);

                    // log action
                    SystemLogController.Create(new SystemLogModel(CurrentUser.User.UserName, "Danh mục {0}".FormatWith(hdfObjName.Text), SystemAction.Create,
                                                                  "Tạo danh mục {0}".FormatWith(model.Name)));
                }

                // show notification
                if (resultModel != null)
                {
                    Dialog.ShowNotification("Lưu thành công");

                    // hide window
                    wdSetting.Hide();

                    // reload data
                    gpCatalog.Reload();
                }
                else
                {
                    Dialog.ShowNotification("Lưu không thành công, Tên đã tồn tại");
                }
            }
            catch (Exception ex)
            {
                // show dilog
                Dialog.ShowError(ex);

                // log exception
                SystemLogController.Create(new SystemLogModel(CurrentUser.User.UserName, "Danh mục {0} - InsertOrUpdate".FormatWith(hdfObjName.Text), ex));
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Init setting window
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void InitWindow(object sender, DirectEventArgs e)
        {
            try
            {
                // init id
                var param = e.ExtraParams["Id"];

                // parse id
                if (int.TryParse(param, out var id))
                {
                    // init window props
                    if (id > 0)
                    {
                        // edit
                        wdSetting.Title = @"Sửa";
                        wdSetting.Icon  = Icon.Pencil;
                    }
                    else
                    {
                        // insert
                        wdSetting.Title = @"Thêm mới";
                        wdSetting.Icon  = Icon.Add;
                    }

                    // init id
                    hdfId.Text = id.ToString();

                    // init object
                    var model = new CatalogModel(hdfObjName.Text);

                    // check id
                    if (id > 0)
                    {
                        var result = CatalogController.GetById(hdfObjName.Text, id);
                        if (result != null)
                        {
                            model = result;
                        }
                    }

                    // set catalog props
                    txtName.Text        = model.Name;
                    txtDescription.Text = model.Description;
                    txtOrder.Text       = model.Order.ToString();
                    hdfGroup.Text       = model.Group;
                    cboGroup.Text       = model.GroupName;
                    hdfStatus.Text      = ((int)model.Status).ToString();
                    cboStatus.Text      = model.Status.Description();

                    // show window
                    wdSetting.Show();
                }
            }
            catch (Exception ex)
            {
                // show dilog
                Dialog.ShowError(ex);

                // log exception
                SystemLogController.Create(new SystemLogModel(CurrentUser.User.UserName, "Danh mục {0} - InitWindow".FormatWith(hdfObjName.Text), ex));
            }
        }