コード例 #1
0
        public async Task <ActionResult <ItemPkgDTO> > UpdateItem([FromBody] ItemPkgDTO dto)
        {
            var Item    = mapper.Map <Item>(dto.Item);
            var Address = mapper.Map <Address>(dto.Address);

            if (Item != null && Address != null)
            {
                ItemPkgDTO pDto = new ItemPkgDTO();

                if (Address.IsDefault)
                {
                    Item.AddressId = Address.Id;
                }
                else
                {
                    pDto.Address   = mapper.Map <AddressDTO>(await UB.UpdateAddress(Address));
                    Item.AddressId = pDto.Address.Id;
                }

                pDto.Item = mapper.Map <ItemDTO>(await IB.UpdateItem(Item));

                return(pDto);
            }
            else
            {
                return(BadRequest("No Item and Address details"));
            }
        }
コード例 #2
0
        public async Task <ActionResult <ItemPkgDTO> > GetItem(int itemNum)
        {
            ItemPkgDTO pDto = new ItemPkgDTO();
            var        Item = mapper.Map <ItemDTO>(await IB.GetItem(itemNum));

            if (Item != null)
            {
                var Address = mapper.Map <AddressDTO>(await UB.GetAddress(Item.AddressId));
                pDto.Item    = Item;
                pDto.Address = Address;
                return(pDto);
            }
            else
            {
                return(BadRequest("Item is not found"));
            }
        }
コード例 #3
0
        public async Task <ActionResult <ItemPkgDTO> > InsertItem([FromBody] ItemPkgDTO dto)
        {
            ItemPkgDTO pDto = new ItemPkgDTO();

            var Item    = mapper.Map <Item>(dto.Item);
            var Address = mapper.Map <Address>(dto.Address);

            if (Address.IsDefault)
            {
                Item.AddressId = Address.Id;
            }
            else
            {
                pDto.Address   = mapper.Map <AddressDTO>(await UB.InsertAddress(Address));
                Item.AddressId = pDto.Address.Id;
            }

            pDto.Item = mapper.Map <ItemDTO>(await IB.InsertItem(Item));

            return(pDto);
        }
コード例 #4
0
        public async Task <ActionResult <List <ItemPkgDTO> > > GetUserItemsAndDefaultPhoto(int currentPage, string userId)
        {
            List <ItemPkgDTO> dtoPkgList = new List <ItemPkgDTO>();

            var Items = await IB.GetItems(userId, currentPage);

            foreach (Item item in Items)
            {
                var Add = await IB.GetItemAddress(item.AddressId);

                var Photo = await IB.GetItemDefaultPhoto(item.Id);

                ItemPkgDTO dto = new ItemPkgDTO()
                {
                    Item    = mapper.Map <ItemDTO>(item),
                    Address = mapper.Map <AddressDTO>(Add)
                };
                dto.Item.DefaultImageFile = (Photo == null) ? null : Photo.FileName;

                dtoPkgList.Add(dto);
            }
            return(dtoPkgList);
        }