Base solution for your next web application

Activities of "rferrari"

I confirm the issue on that part is that you have to replace $modal with $uibModal in both the modal controller and the index one. Look at:

$modal has been renamed to $uibModal in ui-bootstrap 0.14.0: [https://github.com/olov/ng-annotate/issues/200])

Hi,

I have multiple tables with values I want to make appear in dropdown menus in the client during creation or update of entities. Typical case is phonetype for phones. Practically, I should not send anything from the client, just retrieve the complete list of items. I was thinking to use GetAll() or GetAllList() or GetAllListAsync(), but there is no way. I have to give an input and the input it is not to be null.

Can you help me? This is a requirement I have for a lot of items.

Thanks

I was using those, but probably I had issues with my Dtos. Now Everything is working fine. Thanks!

Hi,

I am trying to make multiple addition to a collection at the same time, but it is failing.

Situation is:

The client send a partner (main entity) with phones (or other elements) as a collection. There are 3 cases, the phone has been deleted and it is in a deleted phones list, the phone has been modified or added. I identify the new phones because they have a 0 id so I build the following application service:

[AbpAuthorize(AppPermissions.Pages_Tenant_Partners_CreatePartner)]
        public async Task EditPartner(EditPartnerInput input)
        {
            var partner = input.MapTo<Partner>();
            var phones = input.Phones.MapTo<List<Phone>>();
            var phonesToDelete = input.DeletedPhones.MapTo<List<Phone>>();

            var query = await _partnerRepository.UpdateAsync(partner);

            foreach (var phone in phones)
            {
                if (phone.Id == 0)
                {
                    {
                        var currentPartner = _partnerRepository.Get(partner.Id);
                        currentPartner.Phones.Add(phone);
                      //  await CurrentUnitOfWork.SaveChangesAsync();
                    }
                }
                else
                {
                    var phoneToUpdate = await _phoneRepository.GetAsync(phone.Id);
                    phone.MapTo(phoneToUpdate);
                    await _phoneRepository.UpdateAsync(phoneToUpdate);
                }
            }
            foreach (var phoneToDelete in phonesToDelete)
            {
                await _phoneRepository.DeleteAsync(phoneToDelete.Id);
            }
        }

Everything is working fine:

  1. Multiple deleted phones in the client are deleted in the DB
  2. Multiple edited phones in the client are updated in the DB
  3. If the phone to add is just one it is added

BUT

if I have more than one phone to add I get the following error:

System.InvalidOperationException: Attaching an entity of type 'stake.Partners.Phone' failed because another entity of the same type already has the same primary key value. This can happen when using the 'Attach' method or setting the state of an entity to 'Unchanged' or 'Modified' if any entities in the graph have conflicting key values. This may be because some entities are new and have not yet received database-generated key values. In this case use the 'Add' method or the 'Added' entity state to track the graph and then set the state of non-new entities to 'Unchanged' or 'Modified' as appropriate.

This is obviously related to the fact that the first record is not yet saved when the second one is processed. The suggestion is to use Add, and I am using it!

What I tried:

  1. Used Insert, of course it did not work;
  2. Used Add and CurrentUnitOfWork.SaveChangesAsync(), it is the same;

It seems I should change the state of the item, but I did not find the way.

Please help, thanks!

I would say yes, as I made so many attempts, but I try it again and I tell you.

No way.... same error.

Should I change my Dto?

I tried both, the commented and uncommented:

using Abp.AutoMapper;
using Abp.Application.Services.Dto;
using System.Collections.ObjectModel;

namespace stake.Partners.Dto
{
    [AutoMapTo(typeof(Partner))]
    public class EditPartnerInput : IInputDto
    {
        public int Id { get; set; }

        public string Name { get; set; }

        public string Surname { get; set; }

        //public Collection<PhoneInEditPartnerDto> Phones { get; set; }

        public PartnerPhoneDto[] Phones { get; set; }

        public PartnerPhoneDto[] DeletedPhones { get; set; }
    }
    //[AutoMapTo(typeof(Phone))]
    //public class PhoneInEditPartnerDto : EntityDto
    //{
    //    public string Name { get; set; }

    //    public int PartnerId { get; set; }

    //    public int PhoneTypeId { get; set; }
    //}
}

The phone Dto is:

using Abp.AutoMapper;
using Abp.Application.Services.Dto;

namespace stake.Partners.Dto
{
    [AutoMap(typeof(Phone))]
    public class PartnerPhoneDto : EntityDto
    {
        public string Name { get; set; }

        public int PartnerId { get; set; }

        public int PhoneTypeId { get; set; }
    }
}

Yes it is in application service and here it is last version

[AbpAuthorize(AppPermissions.Pages_Tenant_Partners_CreatePartner)]
        public async Task EditPartner(EditPartnerInput input)
        {
            var partner = input.MapTo<Partner>();
            var phones = input.Phones.MapTo<List<Phone>>();
            var phonesToDelete = input.DeletedPhones.MapTo<List<Phone>>();

            var query = await _partnerRepository.UpdateAsync(partner);

            foreach (var phone in phones)
            {
                if (phone.Id == 0)
                {
                    {
                        //  var currentPartner = _partnerRepository.Get(partner.Id);
                        //  currentPartner.Phones.Add(phone);
                        ////  await CurrentUnitOfWork.SaveChangesAsync();
                        await _phoneRepository.InsertAsync(phone);
                        await CurrentUnitOfWork.SaveChangesAsync();
                    }
                }
                else
                {
                    var phoneToUpdate = await _phoneRepository.GetAsync(phone.Id);
                    phone.MapTo(phoneToUpdate);
                    await _phoneRepository.UpdateAsync(phoneToUpdate);
                }
            }
            foreach (var phoneToDelete in phonesToDelete)
            {
                await _phoneRepository.DeleteAsync(phoneToDelete.Id);
            }
        }

I found this, very similar to what I try to do in a classic book on Entity Framework programming, but we do not have anyway to use it in ABP, for what I know

private static void SaveDestinationAndLodgings(
  Destination destination,
  List<Lodging> deletedLodgings)
{
  // TODO: Ensure only Destinations & Lodgings are passed in

  using (var context = new BreakAwayContext())
  {
    context.Destinations.Add(destination);

    if (destination.DestinationId > 0)
    {
      context.Entry(destination).State = EntityState.Modified;
    }

    foreach (var lodging in destination.Lodgings)
    {
      if (lodging.LodgingId > 0)
      {
        context.Entry(lodging).State = EntityState.Modified;
      }
    }

    foreach (var lodging in deletedLodgings)
    {
      context.Entry(lodging).State = EntityState.Deleted;
    }

    context.SaveChanges();
  }
}

Thanks in advance for your support. Here are my entities:

Partner:

using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
using Abp.Domain.Entities.Auditing;
using System.Collections.Generic;

namespace stake.Partners
{
    [Table("stakePartners")]
    public class Partner : FullAuditedEntity
    {
        public const int MaxNameLength = 50;
        public const int MaxSurnameLength = 50;

        [Required]
        [MaxLength(MaxNameLength)]
        public virtual string Name { get; set; }

        [Required]
        [MaxLength(MaxSurnameLength)]
        public virtual string Surname { get; set; }

        public virtual RelationshipType RelationshipType { get; set; }
        public virtual ResponseLevel ResponseLevel { get; set; }
        public virtual InterestLevel InterestLevel { get; set; }
        public virtual InfluenceLevel InfluenceLevel { get; set; }
        public virtual InfluenceArea InfluenceArea { get; set; }
        public virtual InterestArea InterestArea { get; set; }
        public virtual ReactivityLevel ReactivityLevel { get; set; }
        public virtual LikingLevel LikingLevel { get; set; }

        public virtual ICollection<Phone> Phones { get; set; }
        public virtual ICollection<Social> Socials { get; set; }
        public virtual ICollection<Email> Emails { get; set; }
        public virtual ICollection<Address> Addresses { get; set; }
    }
}

Phone:

using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
using Abp.Domain.Entities.Auditing;
using System.Collections.Generic;

namespace stake.Partners
{
    [Table("stakePhones")]
    public class Phone : FullAuditedEntity
    {
        public const int MaxNumberLength = 16;

        [ForeignKey("PartnerId")]
        public virtual Partner Partner { get; set; }
        public virtual int PartnerId { get; set; }

        [ForeignKey("PhoneTypeId")]
        public virtual PhoneType PhoneType { get; set; }
        public virtual int PhoneTypeId { get; set; }

        [Required]
        [MaxLength(MaxNumberLength)]
        public virtual string Name { get; set; }

    }
}

Phonetype (to complete the chain:

using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
using Abp.Domain.Entities.Auditing;
using System.Collections.Generic;

namespace stake.Partners
{
    [Table("stakePhoneTypes")]
    public class PhoneType : FullAuditedEntity
    {
        public const int MaxNameLength = 50;

        [Required]
        [MaxLength(MaxNameLength)]
        public virtual string Name { get; set; }

        public virtual ICollection<Phone> Phones { get; set; }
    }
}

Could it be some wrong dll version?

here my configs

CORE

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="Abp" version="0.9.5.0" targetFramework="net461" />
  <package id="Abp.AutoMapper" version="0.9.5.0" targetFramework="net461" />
  <package id="Abp.Zero" version="0.9.4.0" targetFramework="net461" />
  <package id="Abp.Zero.Ldap" version="0.9.4.0" targetFramework="net461" />
  <package id="AutoMapper" version="4.2.1" targetFramework="net461" />
  <package id="Castle.Core" version="3.3.3" targetFramework="net451" />
  <package id="Castle.LoggingFacility" version="3.3.0" targetFramework="net451" />
  <package id="Castle.Windsor" version="3.3.0" targetFramework="net451" />
  <package id="Microsoft.AspNet.Identity.Core" version="2.2.1" targetFramework="net451" />
  <package id="Newtonsoft.Json" version="8.0.3" targetFramework="net461" />
  <package id="Nito.AsyncEx" version="3.0.1" targetFramework="net451" />
  <package id="System.Collections.Immutable" version="1.1.36" targetFramework="net461" />
</packages>

EntityFramework

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="Abp" version="0.9.5.0" targetFramework="net461" />
  <package id="Abp.AutoMapper" version="0.9.5.0" targetFramework="net461" />
  <package id="Abp.EntityFramework" version="0.9.5.0" targetFramework="net461" />
  <package id="Abp.EntityFramework.Common" version="0.9.5.0" targetFramework="net461" />
  <package id="Abp.Zero" version="0.9.4.0" targetFramework="net461" />
  <package id="Abp.Zero.EntityFramework" version="0.9.4.0" targetFramework="net461" />
  <package id="AutoMapper" version="4.2.1" targetFramework="net461" />
  <package id="Castle.Core" version="3.3.3" targetFramework="net461" />
  <package id="Castle.LoggingFacility" version="3.3.0" targetFramework="net451" />
  <package id="Castle.Windsor" version="3.3.0" targetFramework="net451" />
  <package id="EntityFramework" version="6.1.3" targetFramework="net451" />
  <package id="EntityFramework.DynamicFilters" version="1.4.10.2" targetFramework="net461" />
  <package id="Microsoft.AspNet.Identity.Core" version="2.2.1" targetFramework="net451" />
  <package id="Newtonsoft.Json" version="8.0.3" targetFramework="net461" />
  <package id="Nito.AsyncEx" version="3.0.1" targetFramework="net451" />
  <package id="System.Collections.Immutable" version="1.1.36" targetFramework="net461" />
</packages>

application

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="Abp" version="0.9.5.0" targetFramework="net461" />
  <package id="Abp.AutoMapper" version="0.9.5.0" targetFramework="net461" />
  <package id="Abp.Zero" version="0.9.4.0" targetFramework="net461" />
  <package id="Abp.Zero.Ldap" version="0.9.4.0" targetFramework="net461" />
  <package id="AutoMapper" version="4.2.1" targetFramework="net461" />
  <package id="Castle.Core" version="3.3.3" targetFramework="net451" />
  <package id="Castle.LoggingFacility" version="3.3.0" targetFramework="net451" />
  <package id="Castle.Windsor" version="3.3.0" targetFramework="net451" />
  <package id="EntityFramework" version="6.1.3" targetFramework="net451" />
  <package id="EPPlus" version="4.0.5" targetFramework="net452" />
  <package id="Microsoft.AspNet.Identity.Core" version="2.2.1" targetFramework="net451" />
  <package id="Newtonsoft.Json" version="8.0.3" targetFramework="net461" />
  <package id="Nito.AsyncEx" version="3.0.1" targetFramework="net451" />
  <package id="SharpZipLib" version="0.86.0" targetFramework="net461" />
  <package id="System.Collections.Immutable" version="1.1.36" targetFramework="net461" />
  <package id="System.Linq.Dynamic" version="1.0.6" targetFramework="net452" />
</packages>
Showing 1 to 10 of 38 entries