Exemplo n.º 1
0
        public async Task <bool> insertAccessgroup(AccessgroupDto accessgroupDto)
        {
            try
            {
                Accessgroup oAccessgroup = Mapper.Map <AccessgroupDto, Accessgroup>(accessgroupDto);
                // var oAccessgroup = new Accessgroup();
                //oAccessgroup.ownerCompanyId = companyId;
                //oAccessgroup.modiferUserId = accessgroupDto.userId;
                //oAccessgroup.groupName = accessgroupDto.groupName;


                foreach (var itmMenuItems in accessgroupDto.menuItemsDto)
                {
                    if (itmMenuItems.isChecked == true)
                    {
                        var itmAccessgroupMenuitem = new AccessgroupMenuitem();
                        itmAccessgroupMenuitem.createdUserId = accessgroupDto.userId;
                        itmAccessgroupMenuitem.menuitemId    = itmMenuItems.id;
                        oAccessgroup.accessgroupMenuitems.Add(itmAccessgroupMenuitem);
                    }
                }
                _Accessgroups.Add(oAccessgroup);

                await _uow.SaveChangesAsync();

                return(true);
            }
            catch
            {
                return(false);
            }
        }
Exemplo n.º 2
0
        public async Task <bool> updateAccessgroup(AccessgroupDto accessgroupDto)
        {
            try
            {
                Accessgroup oAccessgroup = await _Accessgroups
                                           .SingleAsync(x =>
                                                        x.ownerCompanyId == accessgroupDto.ownerCompanyId &&
                                                        x.id == accessgroupDto.id
                                                        );

                oAccessgroup.groupName     = accessgroupDto.groupName;
                oAccessgroup.modiferUserId = accessgroupDto.userId;


                foreach (var oMenuItemDto in accessgroupDto.menuItemsDto)
                {
                    var oFoundAccessgroupMenuitem = await _AccessgroupMenuitems
                                                    .SingleOrDefaultAsync(x =>
                                                                          x.accessgroupId == accessgroupDto.id &&
                                                                          x.menuitemId == oMenuItemDto.id
                                                                          );

                    if (oFoundAccessgroupMenuitem == null)
                    {
                        if (oMenuItemDto.isChecked == true)
                        {
                            var oNewAccessgroupMenuitem = new AccessgroupMenuitem();
                            oNewAccessgroupMenuitem.createdUserId = accessgroupDto.userId;
                            oNewAccessgroupMenuitem.accessgroupId = accessgroupDto.id;
                            oNewAccessgroupMenuitem.menuitemId    = oMenuItemDto.id;
                            _AccessgroupMenuitems.Add(oNewAccessgroupMenuitem);
                        }
                    }
                    else
                    {
                        if (oMenuItemDto.isChecked == false)
                        {
                            _AccessgroupMenuitems.Remove(oFoundAccessgroupMenuitem);
                        }
                    }
                }

                await _uow.SaveChangesAsync();


                return(true);
            }
            catch
            {
                return(false);
            }
        }