Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC

Activities of "jtallon"

No, my project is using 8.0

Any update on this?

Answer

Thanks maliming, that makes sense. I will try that. I appreciate your patience.

Answer

thanks @maliming, here it is:

configuration.CreateMap<Course, CreateOrEditCourseDto>()
    .ForSourceMember(course => course.UserCourses, options => options.DoNotValidate())
    .ForSourceMember(course => course.CourseTrainers, options => options.DoNotValidate())
    .ForSourceMember(course => course.CourseDocuments, options => options.DoNotValidate())
    ;

configuration.CreateMap<CreateOrEditCourseDto, Course>()
    .ForMember(course => course.UserCourses, opt => opt.MapFrom(input => input.TraineeIds
        .Select(traineeId => new UserCourse
        {
            CourseId = input.Id ?? 0,
            UserId = traineeId
        }).ToList()))
    .ForMember(course => course.CourseDocuments, opt => opt.MapFrom(src => src.DocumentIds
        .Select(documentId => new CourseDocument
        {
            CourseId = src.Id ?? 0,
            DocId = documentId
        })))
    .ForMember(course => course.CourseTrainers, opt => opt.MapFrom(src => src.TrainerIds
        .Select(trainerId => new CourseTrainer
        {
            CourseId = src.Id ?? 0,
            TrainerId = trainerId
        })))
    ;
    
 configuration.CreateMap<Course, CourseDto>()
    .ForSourceMember(course => course.UserCourses, options => options.DoNotValidate())
    .ForSourceMember(course => course.CourseTrainers, options => options.DoNotValidate())
    .ForSourceMember(course => course.CourseDocuments, options => options.DoNotValidate())
    ;
Answer

hi @maliming, no problem:

Course

using Bowie.Framework.Portal.General;
using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Abp.Domain.Entities.Auditing;
using System.Collections.Generic;

namespace Bowie.Framework.Portal.Training
{
    [Table("Courses")]
    public class Course : FullAuditedEntity
    {

        [Required]
        public virtual string CourseName { get; set; }
        public virtual string Description { get; set; }
        
        public ICollection<CourseTrainer> CourseTrainers { get; set; }
        public ICollection<CourseDocument> CourseDocuments { get; set; }
        public ICollection<UserCourse> UserCourses { get; set; }
        public CourseCategory CourseCategory { get; set; }
        public virtual int? CourseCategoryId { get; set; }
    }
}

CourseDocument

using Abp.Domain.Entities.Auditing;
using Bowie.Framework.Portal.Document;

namespace Bowie.Framework.Portal.Training
{
    public class CourseDocument : FullAuditedEntity
    {
        public int CourseId { get; set; }
        public Course Course { get; set; }
        public int DocId { get; set; }
        public Doc Doc { get; set; }
    }
}

Doc

using System;
using Bowie.Framework.Portal.Authorization.Users;
using Bowie.Framework.Portal.Training;
using Bowie.Framework.Portal.General;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Abp.Domain.Entities.Auditing;
using System.Collections.Generic;
using System.Linq;
using Bowie.Framework.Portal.CommentThreads;
using JetBrains.Annotations;

namespace Bowie.Framework.Portal.Document
{
    [Table("Docs")]
    public class Doc : FullAuditedEntity
    {
        [Required]
        public virtual string ReferenceID { get; set; }
        [Required]
        public virtual string Title { get; set; }
        public ICollection<CourseDocument> CourseDocuments { get; set; }
        public ICollection<DocumentTrainer> DocumentTrainers { get; set; }
        public ICollection<DocumentPosition> DocumentPositions { get; set; }
        public ICollection<DocumentApprover> DocumentApprovers { get; set; }
    }
}

CreateOrEditCourseDto


using System;
using Abp.Application.Services.Dto;
using System.ComponentModel.DataAnnotations;
using System.Collections.Generic;

namespace Bowie.Framework.Portal.Training.Dtos
{
    public class CreateOrEditCourseDto : EntityDto<int?>
    {
        [Required]
        public string CourseName { get; set; }
        public string Description { get; set; }
        
        public IEnumerable<int> DocumentIds { get; set; }
        public IEnumerable<int> TraineeIds { get; set; } //user
        public IEnumerable<int> TrainerIds { get; set; }
        public int? CourseCategoryId { get; set; }

    }
}
Answer

Hi @ryancyq,

In my portalEntityFrameworkCoreModule I have uncommented the two lines:

Configuration.EntityHistory.Selectors.Add("PortalEntities", EntityHistoryHelper.TrackedTypes);
Configuration.CustomConfigProviders.Add(new EntityHistoryConfigProvider(Configuration));

Hi @maliming,

I am using ASPNetZero version: 6.8.0 EF: core

The create/edit code is:

[AbpAuthorize(AppPermissions.Pages_Courses_Create)]
private async Task<int> Create(CreateOrEditCourseDto input)
{
    var course = ObjectMapper.Map<Course>(input);

    var newCourseId = await _courseRepository.InsertAndGetIdAsync(course);
    return newCourseId;
}

[AbpAuthorize(AppPermissions.Pages_Courses_Edit)]
private async Task<int> Update(CreateOrEditCourseDto input)
{      
    var courseEntity = ObjectMapper.Map<Course>(input);
    var course = await _courseRepository.UpdateAsync(courseEntity);                
    return (int)input.Id;
}

The CreateOrEditCourseDto in the code has public IEnumerable<int> DocumentIds { get; set; }

within my PortalDBContext I have the following:

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
    base.OnModelCreating(modelBuilder);
    modelBuilder.Entity<CourseDocument>()
     .HasKey(bc => new { bc.CourseId, bc.DocId });
        modelBuilder.Entity<CourseDocument>()
            .HasOne(bc => bc.Course)
            .WithMany(b => b.CourseDocuments)
            .HasForeignKey(bc => bc.CourseId);
        modelBuilder.Entity<CourseDocument>()
            .HasOne(bc => bc.Doc)
            .WithMany(c => c.CourseDocuments)
            .HasForeignKey(bc => bc.DocId);
        modelBuilder.Entity<CourseDocument>().Ignore(c => c.Id);
        
        ///
 }
Question

I created a new entity. I would like to view the change logs for it.

It currently looks like this:

public class CourseDocument : FullAuditedEntity
    {
        public int CourseId { get; set; }
        public Course Course { get; set; }
        public int DocId { get; set; }
        public Doc Doc { get; set; }
    }

I've added the type to the tracked types:

namespace Bowie.Framework.Portal.EntityHistory
{
    public static class EntityHistoryHelper
    {
        public const string EntityHistoryConfigurationName = "EntityHistory";

        public static readonly Type[] HostSideTrackedTypes =
        {
            typeof(CourseDocument)
        };

        public static readonly Type[] TenantSideTrackedTypes =
        {
            typeof(CourseDocument)
        };

        public static readonly Type[] TrackedTypes =
            HostSideTrackedTypes
                .Concat(TenantSideTrackedTypes)
                .GroupBy(type => type.FullName)
                .Select(types => types.First())
                .ToArray();
    }
}

I then added the migration and updated the DB.

I was hoping to see the DocId and CourseID with their new values. Instead I just get no sign of them:

The DocId and CourseID appear correctly in the DB:

Hi @mahartha and @ismcagdas,

Did this issue get sorted out?

Thanks for the info ismcagdas

Sure thing. Its a "Course" entity. The issue is with both startDate and endDate The create-or-edit-course-modal.component.html

<div class="form-group">
    <label for="Course_EndDate">{{l("EndDate")}}</label>
    <input 
        required 
        class="form-control m-input" 
        type="datetime" 
        bsDatepicker 
        [(ngModel)]="course.endDate._d" 
        id="Course_EndDate" 
        name="Course_EndDate">
</div>

The front end then looks like this:

The values look correct coming into the service-proxies.ts:

However the JSON.stringify returns the following:

The database then saves it as: 2019-04-02 23:00:00.0000000

Note: our time zone is (IST) Irish Standard Time The offset is : UTC/GMT +1 hour

I was expecting it to work out of the box... will I have to add something like this:

fixDate(d: Date): Date {
  d.setHours(d.getHours() - d.getTimezoneOffset() / 60);
  return d;
}
Showing 61 to 70 of 86 entries