private void btnOk_Click(object sender, EventArgs e)
        {
            var amount = (int)this.numberAmount.Value;

            if (amount <= 0)
            {
                MessageBox.Show("Số lượng phải lớn hơn 0", "Cánh báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            var check = MessageBox.Show("Xác nhận số lượng nhập là " + amount + " ?", "Xác nhận", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);

            if (check.Equals(DialogResult.Cancel))
            {
                return;
            }

            _model = new ItemRelation(0, _selectedItemId, amount);
            _relations.Add(_model);
            var res = _modifieds.Where(m => m.ChildId.Equals(_model.ChildId));

            if (res.Any())
            {
                res.First().Amount = amount;
            }
            else
            {
                _modifieds.Add(_model);
            }

            this.DialogResult = DialogResult.OK;
            this.Close();
        }
Exemple #2
0
        /// <summary>
        /// Create new relation between 2 items
        /// </summary>
        /// <param name="firstItemId">Id of first item</param>
        /// <param name="secondItemId">Id of second item</param>
        /// <param name="userId">id of loginned user</param>
        /// <returns>Response with success message</returns>
        /// <exception cref="ForbiddenResponseException">User don't have access to relate items</exception>
        public async Task <ItemResponse> CreateRecordAsync(int firstItemId, int secondItemId, string userId)
        {
            // Get 2 items
            var firstItem = await _itemRepository.ReadAsync(firstItemId);

            var secondItem = await _itemRepository.ReadAsync(secondItemId);

            // Get user role
            var userRole = await GetUserRoleAsync(firstItem.SprintId, userId);

            // User must be part of team to create relation
            if (!userRole.IsPartOfTeam())
            {
                throw new ForbiddenResponseException("Yuo don't have access to create relations!");
            }

            // Check if this relation already exist
            var existRelation = await _itemRelationRepository.GetRecordAsync(firstItemId, secondItemId);

            var existRelation2 = await _itemRelationRepository.GetRecordAsync(secondItemId, firstItemId);

            if (existRelation != null || existRelation2 != null)
            {
                throw new ForbiddenResponseException("This relation is already exist!");
            }

            // Create relation
            var relation = new ItemRelation {
                FirstItemId = firstItem.Id, SecondItemId = secondItem.Id
            };
            await _itemRelationRepository.CreateRecordAsync(relation);

            return(new ItemResponse(true, "Related!"));
        }
        private static void HandleViewHolderBound(RecyclerView.ViewHolder holder, ItemRelation relation, TData data)
        {
            var viewHolder = (TreeMenuAdapterViewHolder <TData>)holder;

            viewHolder.Cell.Data     = data;
            viewHolder.Cell.Relation = relation;
        }
        public ItemRelationViewModel(IViewModelsFactory <ISearchItemViewModel> vmFactory, ItemRelation item, IItemViewModel parent)
        {
            _vmFactory = vmFactory;
            InnerItem  = item;
            Parent     = parent;

            ItemPickCommand      = new DelegateCommand(RaiseItemPickInteractionRequest);
            CommonConfirmRequest = new InteractionRequest <Confirmation>();
        }
 public EditItemRelationDialog(IUnitOfWork unitOfWork, ItemRelation relation, IList <ItemRelation> modifieds)
 {
     InitializeComponent();
     _unitOfWork = unitOfWork;
     _modifieds  = modifieds;
     if (relation is null)
     {
         MessageBox.Show("Chi tiết truyền vào không tìm thấy", "Cảnh báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
         this.Close();
     }
     _model = relation;
 }
Exemple #6
0
        private void gridSubItem_SelectionChanged(object sender, EventArgs e)
        {
            if (this.gridSubItem.SelectedRows.Count > 0)
            {
                var row = this.gridSubItem.SelectedRows[0];
                _selectedIndex = row.Index;

                var childId = (Int32)row.Cells["ChildId"].Value;
                _selectedRelation = _relations.Where(m => m.ChildId.Equals(childId)).First();
            }
            else
            {
                _selectedRelation = null;
            }
        }
Exemple #7
0
        public async Task Check_DeleteNotExistRelationThrowsException(int firstId, int secondId)
        {
            //Arrange
            var cls = new InMemoryAppDbContext();

            using (var context = cls.GetContextWithData())
            {
                IItemRelationRepository repo          = new ItemRelationRepository(context);
                ItemRelation            startRelation = context.ItemsRelations.Find(firstId, secondId);
                startRelation.FirstItemId -= 100;
                await Assert.ThrowsAsync <InvalidOperationException>(() => repo.DeleteRecordAsync(startRelation));

                context.Database.EnsureDeleted();
            }
        }
Exemple #8
0
        public async Task Check_GetNotExistRecordReturnsNull(int firstId, int secondId)
        {
            //Arrange
            var cls = new InMemoryAppDbContext();

            using (var context = cls.GetContextWithData())
            {
                IItemRelationRepository repo             = new ItemRelationRepository(context);
                ItemRelation            expectedRelation = context.ItemsRelations.Find(firstId, secondId);
                ItemRelation            actualRelation   = await repo.GetRecordAsync(firstId, secondId);

                Assert.Null(actualRelation);
                Assert.Equal(expectedRelation, actualRelation);
                context.Database.EnsureDeleted();
            }
        }
 private void gridItem_SelectionChanged(object sender, EventArgs e)
 {
     if (this.gridItem.SelectedRows.Count > 0)
     {
         var row = this.gridItem.SelectedRows[0];
         _selectedIndex  = row.Index;
         _selectedItemId = (Int32)row.Cells["Id"].Value;
         btnOk.Enabled   = true;
     }
     else
     {
         btnOk.Enabled   = false;
         _selectedIndex  = -1;
         _selectedItemId = 0;
         _model          = null;
     }
 }
    private static void ShowItem(ItemRelation itemRelation, int indent = 0)
    {
        EditorGUILayout.Space(EditorGUIUtility.singleLineHeight * 1.5f);

        var lastRect = GUILayoutUtility.GetLastRect();

        var buttonRect = new Rect(lastRect.x + (ItemIndentX * indent), lastRect.y, 8 * (itemRelation.Item.name.Length + 2), EditorGUIUtility.singleLineHeight);

        if (GUI.Button(buttonRect, itemRelation.Item.name))
        {
            Selection.activeGameObject = itemRelation.Item.gameObject;
        }

        var id = itemRelation.Item.GetInstanceID();

        foreach (var c in itemRelation.Children.Where(x => x.Parent.Item.GetInstanceID() == id))
        {
            ShowItem(c, indent + 1);
        }
    }
Exemple #11
0
        public async Task Check_DeleteRelationWorkingRight(int firstId, int secondId)
        {
            //Arrange
            var cls = new InMemoryAppDbContext();

            using (var context = cls.GetContextWithData())
            {
                IItemRelationRepository repo          = new ItemRelationRepository(context);
                ItemRelation            startRelation = context.ItemsRelations.Find(firstId, secondId);

                await repo.DeleteRecordAsync(startRelation);

                var actualRelation = context.ItemsRelations.Find(firstId, secondId);

                Assert.NotNull(startRelation);
                Assert.Null(actualRelation);

                context.Database.EnsureDeleted();
            }
        }
        public void ItemRelations_Create()
        {
            var anItemRelation = new ItemRelation
            {
                Id = 0
            };

            // Set test Create method w/o parameters
            request.Setup(m => m.Post <Response <ItemRelation> >("item_relations", anItemRelation, null)).Returns(new Response <ItemRelation>
            {
                Data = new ItemRelation
                {
                    Id = 1234
                }
            });

            // Test Get method
            var result = itemRelationsProxy.Create(anItemRelation);

            // Verify test
            Assert.IsNotNull(result);
            Assert.IsTrue(result.IsSuccessful);
            Assert.AreEqual(1234, result.Data.Id);
        }
Exemple #13
0
        private UICollectionViewCell GetCell(UICollectionView collectionView, NSIndexPath indexPath, ItemRelation relation, TData data)
        {
            var cell = (TreeMenuCell <TData>)collectionView.DequeueReusableCell(_cellIdentifier, indexPath);

            cell.Data     = data;
            cell.Relation = relation;
            return(cell);
        }
Exemple #14
0
 /// <summary>
 /// Delete specific relation from database
 /// </summary>
 /// <param name="relation">Specific relation to delete</param>
 public async Task DeleteRecordAsync(ItemRelation relation)
 {
     _context.ItemsRelations.Remove(relation);
     await _context.SaveChangesAsync();
 }
Exemple #15
0
        /// <summary>
        /// Create new relation in database
        /// </summary>
        /// <param name="relation">New Relation object</param>
        public async Task CreateRecordAsync(ItemRelation relation)
        {
            await _context.ItemsRelations.AddAsync(relation);

            _context.SaveChanges();
        }
Exemple #16
0
        public void CreateItemEquivalent(string requestXml)
        {
            XDocument xml = XDocument.Parse(requestXml);

            SessionManager.VolatileElements.ClientRequest = xml;

            //check if any item is already in equivalent
            List <Item[, ]> alreadyRelatedItems = new List <Item[, ]>();
            List <Item[, ]> items       = new List <Item[, ]>();//new List<Item[,]>();
            List <Item>     itemsToSave = new List <Item>();
            Item            i;

            foreach (XElement element in xml.Root.Elements())
            {
                Item[,] para = new Item[1, 2];
                IBusinessObject bo          = this.Mapper.LoadBusinessObject(BusinessObjectType.Item, new Guid(element.Attribute("id").Value));
                IBusinessObject relatedItem = null;

                //add related item if exists
                //TODO relacje dwustronne jak brakuje elementu
                if (element.Attribute("relatedItemId") != null)
                {
                    relatedItem = this.Mapper.LoadBusinessObject(BusinessObjectType.Item, new Guid(element.Attribute("relatedItemId").Value));
                }

                para[0, 0] = (Item)bo;
                para[0, 1] = (Item)relatedItem;

                // Dodanie obiektu powiązanego, przypadek tworzenia relacji każdy z każdym
                if (para[0, 1] == null)
                {
                    foreach (XElement el in xml.Root.Elements())
                    {
                        if (element.Attribute("id").Value != el.Attribute("id").Value)
                        {
                            relatedItem = this.Mapper.LoadBusinessObject(BusinessObjectType.Item, new Guid(el.Attribute("id").Value));
                            para[0, 1]  = (Item)relatedItem;
                            items.Add(para);
                        }
                    }
                }
                else
                {
                    items.Add(para);
                }



                //Pętla po relacjach towaru
                foreach (ItemRelation relation in para[0, 0].Relations.Children)
                {
                    //Szukamy relacji tego samego typu
                    if (relation.ItemRelationTypeName == ItemRelationTypeName.Item_Equivalent)
                    {
                        if (para[0, 1].Id == relation.RelatedObject.Id)
                        {
                            alreadyRelatedItems.Add(para);
                        }
                    }
                }
            }


            foreach (Item[,] it in items)
            {
                if (!alreadyRelatedItems.Contains(it))
                {
                    Boolean sameItem = false;
                    Int16   index    = 0;
                    i = it[0, 0];

                    foreach (Item itm in itemsToSave)
                    {
                        if (itm.Id.ToString() == it[0, 0].Id.ToString())
                        {
                            sameItem = true;
                            i        = itemsToSave[index];
                        }
                        index++;
                    }

                    ItemRelation rel = i.Relations.CreateNew();
                    rel.Id = Guid.NewGuid();
                    rel.ItemRelationTypeName = ItemRelationTypeName.Item_Equivalent;
                    IBusinessObject bo = it[0, 1];

                    rel.RelatedObject = bo;

                    if (!sameItem)
                    {
                        itemsToSave.Add(i);
                    }
                }
            }

            this.SaveBusinessObjects(itemsToSave.ToArray());
        }
Exemple #17
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (String.IsNullOrWhiteSpace(txtName.Text))
            {
                MessageBox.Show("Tên không được để trống", "Cánh báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            if (_unitOfWork.ItemRepos.GetAll().Select(m => m.Name).Contains(txtName.Text.Trim()))
            {
                MessageBox.Show("Tên đã tồn tại", "Cánh báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            if (_isForCombo && _relations.Count == 0)
            {
                MessageBox.Show("Combo không được để trống", "Cánh báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            var check = MessageBox.Show("Xác nhận thao tác?", "Xác nhận", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);

            if (check.Equals(DialogResult.Cancel))
            {
                return;
            }

            this.ReturnModel();
            if (_isForCombo)
            {
                if (_isEditMode)
                {
                    _unitOfWork.ItemRepos.Update(_model);
                    foreach (ItemRelation c in _relationsDeleted)
                    {
                        var res = _model.ConsistOf.Where(m => m.ChildId.Equals(c.ChildId));
                        if (res.Any())
                        {
                            _unitOfWork.ItemRepos.ItemRelationRepos.Delete(res.First());
                        }
                    }
                    foreach (ItemRelation c in _relationsModified)
                    {
                        var res = _model.ConsistOf.Where(m => m.ChildId.Equals(c.ChildId));
                        if (res.Any())
                        {
                            var temp = res.First();
                            temp.Copy(c);
                            _unitOfWork.ItemRepos.ItemRelationRepos.Update(res.First());
                        }
                        else
                        {
                            var temp = new ItemRelation(c);
                            temp.ParentId = _model.Id;
                            _unitOfWork.ItemRepos.ItemRelationRepos.Add(temp);
                        }
                    }
                }
                else
                {
                    _model = _unitOfWork.ItemRepos.Add(_model);
                    foreach (ItemRelation rel in _relations)
                    {
                        rel.ParentId = _model.Id;
                        rel.Child    = null;
                    }
                    _unitOfWork.ItemRepos.ItemRelationRepos.AddRange(_relations);
                }
            }
            else
            {
                if (_isEditMode)
                {
                    _unitOfWork.ItemRepos.Update(_model);
                }
                else
                {
                    _model = _unitOfWork.ItemRepos.Add(_model);
                }
            }

            this.DialogResult = DialogResult.OK;
            this.Close();
        }
Exemple #18
0
        /// <summary>
        /// Creates the item equivalent group using specified xml item list.
        /// </summary>
        /// <param name="requestXml">Client's request containing list of items to bind into one equivalent group.</param>
        public void CreateItemEquivalentGroup(string requestXml)
        {
            XDocument xml = XDocument.Parse(requestXml);

            SessionManager.VolatileElements.ClientRequest = xml;

            Item[] items = new Item[xml.Root.Elements().Count()];
            int    i     = 0;

            foreach (XElement element in xml.Root.Elements())
            {
                IBusinessObject bo = this.Mapper.LoadBusinessObject(BusinessObjectType.Item, new Guid(element.Attribute("id").Value));

                items[i++] = (Item)bo;
            }

            //check if any item is already in other equivalent group
            List <Item> alreadyRelatedItems = new List <Item>();
            Guid?       itemEqGrpId         = null;

            foreach (Item item in items)
            {
                foreach (ItemRelation relation in item.Relations.Children)
                {
                    if (relation.ItemRelationTypeName == ItemRelationTypeName.Item_EquivalentGroup)
                    {
                        if (itemEqGrpId == null)
                        {
                            itemEqGrpId = new Guid(((CustomBusinessObject)relation.RelatedObject).Value.Element("id").Value);
                        }
                        else if (itemEqGrpId != new Guid(((CustomBusinessObject)relation.RelatedObject).Value.Element("id").Value))
                        {
                            throw new ClientException(ClientExceptionId.ItemEquivalentGroupException, null, "itemName:" + item.Name);
                        }

                        alreadyRelatedItems.Add(item);
                    }
                }
            }

            if (itemEqGrpId == null)
            {
                itemEqGrpId = Guid.NewGuid();
            }

            foreach (Item item in items)
            {
                if (!alreadyRelatedItems.Contains(item))
                {
                    ItemRelation rel = item.Relations.CreateNew();
                    rel.ItemRelationTypeName = ItemRelationTypeName.Item_EquivalentGroup;
                    CustomBusinessObject bo = CustomBusinessObject.CreateEmpty();

                    bo.Id = itemEqGrpId;
                    bo.Value.Add(new XElement("id", itemEqGrpId.ToUpperString()));

                    rel.RelatedObject = bo;
                }
            }

            this.SaveBusinessObjects(items);
        }
        private static void HandleItemStateChanged(RecyclerView.ViewHolder holder, ItemRelation relation)
        {
            var viewHolder = (TreeMenuAdapterViewHolder <TData>)holder;

            viewHolder.Cell.Relation = relation;
        }
        internal AppDbContext InsertDataToDB(AppDbContext context)
        {
            Project project1 = new Project {
                Id = 1, Name = "First Project", Description = "Some description to Project1"
            };
            Project project2 = new Project {
                Id = 2, Name = "Second Project", Description = "Some description to Project2"
            };

            Sprint sprint1 = new Sprint {
                Id = 1, ProjectId = 1, StartDate = DateTime.Today, Name = "Sprint 1", Description = "Sprint descr 1", EndDate = DateTime.Today.AddDays(7)
            };
            Sprint sprint2 = new Sprint {
                Id = 2, ProjectId = 1, StartDate = DateTime.Today, Name = "Sprint 1", Description = "Sprint descr 1", EndDate = DateTime.Today.AddDays(7)
            };

            Item item1 = new Item {
                Id = 1, SprintId = 1, AssignedUserId = "2138b181-4cee-4b85-9f16-18df308f387d", Name = "Item Name1", Description = "Description Item1", StatusId = 1, TypeId = 1, IsArchived = false, ParentId = null, StoryPoint = 2
            };
            Item item2 = new Item {
                Id = 2, SprintId = 1, AssignedUserId = "2514591e-29f0-4a63-b0ad-87a3e7ebec3d", Name = "Item Name2", Description = "Description Item2", StatusId = 2, TypeId = 2, IsArchived = false, ParentId = 1, StoryPoint = 2
            };
            Item item3 = new Item {
                Id = 3, SprintId = 2, AssignedUserId = "421cb65f-a76d-4a73-8a1a-d792f37ef992", Name = "Item Name3", Description = "Description Item3", StatusId = 3, TypeId = 1, IsArchived = true, ParentId = 1, StoryPoint = 2
            };
            Item item4 = new Item {
                Id = 4, SprintId = 2, AssignedUserId = "54bfd1f9-d379-4930-9c3b-4c84992c028e", Name = "Item Name4", Description = "Description Item4", StatusId = 3, TypeId = 1, IsArchived = false, ParentId = 2, StoryPoint = 2
            };
            Item item5 = new Item {
                Id = 5, SprintId = 2, AssignedUserId = "54bfd1f9-d379-4930-9c3b-4c84992c028e", Name = "Item Name5", Description = "Description Item5", StatusId = 3, TypeId = 1, IsArchived = true, ParentId = null, StoryPoint = 2
            };

            Comment comment1 = new Comment {
                Id = 1, ItemId = 1, Text = "Comment text1", UserId = "2138b181-4cee-4b85-9f16-18df308f387d", Date = DateTime.Today
            };
            Comment comment2 = new Comment {
                Id = 2, ItemId = 2, Text = "Comment text2", UserId = "421cb65f-a76d-4a73-8a1a-d792f37ef992", Date = DateTime.Today
            };

            Status status1 = new Status {
                Id = 1, Name = "New"
            };
            Status status2 = new Status {
                Id = 2, Name = "Approved"
            };
            Status status3 = new Status {
                Id = 3, Name = "Done"
            };

            ItemType itemType1 = new ItemType {
                Id = 1, Name = "UserStory"
            };
            ItemType itemType2 = new ItemType {
                Id = 2, Name = "Task"
            };
            ItemType itemType3 = new ItemType {
                Id = 3, Name = "Bug"
            };
            ItemType itemType4 = new ItemType {
                Id = 4, Name = "Test"
            };

            User user1 = new User {
                Id = "2138b181-4cee-4b85-9f16-18df308f387d", UserName = "******", NormalizedUserName = "******", PasswordHash = "MyPass", FirstName = "Bart", LastName = "Simpson", Email = "*****@*****.**", Info = "in-memory user"
            };
            User user2 = new User {
                Id = "2514591e-29f0-4a63-b0ad-87a3e7ebec3d", UserName = "******", NormalizedUserName = "******", PasswordHash = "MyPass", FirstName = "Lisa", LastName = "Simpson", Email = "*****@*****.**", Info = "in-memory user"
            };
            User user3 = new User {
                Id = "421cb65f-a76d-4a73-8a1a-d792f37ef992", UserName = "******", NormalizedUserName = "******", PasswordHash = "MyPass", FirstName = "Homer", LastName = "Simpson", Email = "*****@*****.**", Info = "in-memory user"
            };
            User user4 = new User {
                Id = "54bfd1f9-d379-4930-9c3b-4c84992c028e", UserName = "******", NormalizedUserName = "******", PasswordHash = "MyPass", FirstName = "Marge", LastName = "Simpson", Email = "*****@*****.**", Info = "in-memory user"
            };

            AppUserRole appUserRole1 = new AppUserRole {
                Id = 1, Name = "NoMember"
            };
            AppUserRole appUserRole2 = new AppUserRole {
                Id = 2, Name = "Owner"
            };
            AppUserRole appUserRole3 = new AppUserRole {
                Id = 3, Name = "ScrumMaster"
            };
            AppUserRole appUserRole4 = new AppUserRole {
                Id = 4, Name = "Developer"
            };
            AppUserRole appUserRole5 = new AppUserRole {
                Id = 5, Name = "Observer"
            };

            ItemRelation relation1 = new ItemRelation {
                FirstItemId = 1, SecondItemId = 2
            };
            ItemRelation relation2 = new ItemRelation {
                FirstItemId = 1, SecondItemId = 3
            };
            ItemRelation relation3 = new ItemRelation {
                FirstItemId = 1, SecondItemId = 4
            };
            ItemRelation relation4 = new ItemRelation {
                FirstItemId = 4, SecondItemId = 7
            };
            ItemRelation relation5 = new ItemRelation {
                FirstItemId = 4, SecondItemId = 8
            };
            ItemRelation relation6 = new ItemRelation {
                FirstItemId = 6, SecondItemId = 2
            };
            ItemRelation relation7 = new ItemRelation {
                FirstItemId = 2, SecondItemId = 9
            };

            context.AppUserRoles.AddRange(new[]
            {
                AppUserRole.None,
                AppUserRole.Owner,
                AppUserRole.ScrumMaster,
                AppUserRole.Developer,
                AppUserRole.Observer
            });
            context.Comments.AddRange(new[] { comment1, comment2 });
            context.Projects.AddRange(new[] { project1, project2 });
            context.Sprints.AddRange(new[] { sprint1, sprint2 });
            context.Items.AddRange(new[] { item1, item2, item3, item4 });
            context.Statuses.AddRange(new[] { status1, status2, status3 });
            context.ItemTypes.AddRange(new[] { itemType1, itemType2 });
            context.Users.AddRange(new[] { user1, user2, user3, user4 });
            context.ItemsRelations.AddRange(new[] { relation1, relation2, relation3, relation4, relation5, relation6, relation7 });

            context.SaveChanges();
            return(context);
        }
 public ItemRelation(ItemRelation relation)
 {
     this.Copy(relation);
 }
Exemple #22
0
        private static void HandleItemStateChanged(UICollectionViewCell collectionViewCell, ItemRelation relation)
        {
            var cell = (TreeMenuCell <TData>)collectionViewCell;

            cell.Relation = relation;
        }
 public void Copy(ItemRelation relation)
 {
     ParentId = relation.ParentId;
     ChildId  = relation.ChildId;
     Amount   = relation.Amount;
 }