Base solution for your next web application

Activities of "patrickglaudemans"

My last sentence was not quite clear. What I ment to say is that is has something to do with the user entity not being monitored for changes by the Entity Framework.

Halil any comments? Thanks, Patrick

Hi,

Thanks for your reply. Last time I provided incomplete code for the example - that's where the null check failed but that is irrelevant. Here is, however, the complete method code. Still the users are not get saved, al other properties like reports, do! THis code is in exact the same appservice structure like recommended in manual etc.

public async Task UpdateContentGroupMembers(UpdateContentGroupMembersInput input)
        {

            if (input != null)
            {
                ContentGroup contentGroup = null;
                if (input.ReportMembers != null)
                {
                    if (input.ReportMembers.Any())
                    {
                        contentGroup = _contentGroupRepository.GetAll()
                            .Include(c=>c.Reports)
                            .Include(c=>c.Users).FirstOrDefault();
                        if (contentGroup != null)
                        {
                            //check if selection is in saved selection - if not add
                            foreach (var selection in input.ReportMembers)
                            {
                                if (contentGroup.Reports.Find(r => r.Id == selection) == null)
                                {
                                    //selected but not yet in saved selection: add
                                    contentGroup.Reports.Add(_reportRepository.Get(selection));
                                }
                            }
                            //check if selection is in saved
                            foreach (var savedSelection in contentGroup.Reports)
                            {
                                if (!input.ReportMembers.Contains(savedSelection.Id))
                                {
                                    //in saved but not selected anymore: delete
                                    contentGroup.Reports.Remove(savedSelection);
                                }
                            }  
                        }
                    }

                    if (input.UserMembers != null)
                    {
                        if (input.UserMembers.Any())
                        {
                            if (contentGroup == null)
                            {
                                contentGroup = _contentGroupRepository.GetAll()
                                    .Include(c => c.Reports)
                                    .Include(c => c.Users).FirstOrDefault();
                            }
                            if (contentGroup != null)
                            {
                                //check if selection is in saved selection - if not add
                                foreach (var selection in input.UserMembers)
                                {
                                    if (contentGroup.Users.Find(r => r.Id == selection) == null)
                                    {
                                        //selected but not yet in saved selection: add
                                        var user = await UserManager.GetUserByIdAsync(System.Convert.ToInt64(selection));
                                        contentGroup.Users.Add(user);
                                    }
                                }
                                //check if selection is in saved
                                foreach (var savedSelection in contentGroup.Users)
                                {
                                    if (!input.UserMembers.Contains(System.Convert.ToInt32(savedSelection.Id)))
                                    {
                                        //in saved but not selected anymore: delete
                                        contentGroup.Users.Remove(savedSelection);
                                    }
                                }

                            }
                        }
                        contentGroup.Users.Add(new User());
                    }
                }

               



                if (contentGroup != null)
                {
                    await _contentGroupRepository.UpdateAsync(contentGroup);    
                }
                else
                {
                    //nothing to do - bye
                }
            }

        }

Best,

Hi,

contentGroup.Users.Add(new User());

can be ignored - it was for testing p.

Thanks! Let me check again. If it keeps on failing I will sent requested code items.

Thanks, but can you supply proper link - link is broken!

pglaudemans

thanks!

Hold it - I solved it. Obviously it had something to do with dependencies to other libraries in the project. To begin with the data layer ;-)

Hi,

public class CreateOrUpdateJobInput : IInputDto { [Required] public JobEditDto Job { get; set; } }

[AutoMapFrom(typeof(Job))] [AutoMapTo(typeof(Job))] public class JobEditDto : FullAuditedEntityDto { public Report Report { get; set; } public string CronSchedule { get; set; } public ReportOutputType OutputType { get; set; } public DateTime? LastRun { get; set; } public bool Active { get; set; } public string Destination { get; set; } }

Hi,

Thanks for thinking with me :-) I'm currently testing a procedure with in I added ReportId property to Entity Job (definition in .core) and change the dto property report into reportId.

I'll update in a sec.

Hi,

Way to go! Yes, we should not use entity objects in dto's and yes, you can add the Id of an entity in the definition of an entity like copied below. Then you can set the proper id yourself without the use of instances of the object, in this case report.

Furthermore, set the property Report to virtual when you want it to be lazy loaded!

public class Job : EntityBase
    {
        public int ReportId { get; set; }
        public virtual Report Report { get; set; }
        public string CronSchedule { get; set; }
        public ReportOutputType OutputType { get; set; }
        public DateTime LastRun { get; set; }
        public bool Active { get; set; }
        public string Destination { get; set; }
    }
Showing 1 to 10 of 29 entries