Base solution for your next web application

Activities of "mpm"

This turned out to be a dumb mistake on my part. I forgot to define an IDbSet for each entity in my second database context. :roll:

Working flawlessly now!

Question

I'm having a few issues getting a second context to a vended app database wired up properly (second context should not use code first). The specific error I am getting when attempting to run 'abp.services.app.vended.getAttributes()' is 'error detail not sent by server', with a response of '{"message":"An error has occurred."}'.

I've looked at the MultiContextDemo app, and think I have things wired up properly, but I am obviously missing something.

CSDataModule

[DependsOn(typeof(AbpZeroEntityFrameworkModule), typeof(CSCoreModule))]
    public class CSDataModule : AbpModule
    {
        public override void PreInitialize()
        {
            Database.SetInitializer(new CreateDatabaseIfNotExists<CSDbContext>());
            
            //web.config (or app.config for non-web projects) file should contain a connection string named "Default".
            Configuration.DefaultNameOrConnectionString = "Default";
        }

        public override void Initialize()
        {
            IocManager.RegisterAssemblyByConvention(Assembly.GetExecutingAssembly());
            Database.SetInitializer<VendedDbContext>(null);
        }
    }

VendedDbContext

public class VendedDbContext : AbpDbContext
    {
        public VendedDbContext()
            : base("Vended")
        {
            
        }
    }

Attribute Class

using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Abp.Domain.Entities;

namespace MCMT.CS.Vended
{
   /// <summary>
    /// A class which represents the Attribute table.
    /// </summary>
	[Table("Attribute")]
    public class Attribute : Entity
    {
        [Key]
        public virtual int AttributeID { get; set; }
        public virtual int ResourceTypeID { get; set; }
        public virtual string Name { get; set; }
        public virtual int AttributeTypeID { get; set; }
        public virtual int? SortOrder { get; set; }
        public virtual string DefaultValue { get; set; }
        public virtual byte? ResNameIndex { get; set; }
        public virtual bool IsUnique { get; set; }
        public virtual byte? RepNameIndex { get; set; }
        public virtual string RepNameFormat { get; set; }
        public virtual bool IsCertification { get; set; }
        public virtual bool IsPublic { get; set; }
        public virtual int? SpecialTypeID { get; set; }
        public virtual bool ShowOnTimesheet { get; set; }
        public virtual bool IsSelfServe { get; set; }
        public virtual string CertType { get; set; }
        public virtual int? CertWarnDays { get; set; }
        public virtual int? CertExpireDays { get; set; }
        public virtual string CertExpireValue { get; set; }
        public virtual bool IsContact { get; set; }
        public virtual int? CertValueOperator { get; set; }
        public virtual bool CertIgnoreNull { get; set; }
        public virtual bool CertForbidPunch { get; set; }
    }
}

Vended App Service Interface

using System.Collections.Generic;
using Abp.Application.Services;

namespace MCMT.CS.Vended
{
    public interface IVendedAppService : IApplicationService
    {
        List<Attribute> GetAttributes();
    }
}

Vended App Service

using System.Collections.Generic;
using System.Linq;
using Abp.Auditing;
using Abp.Domain.Repositories;

namespace MCMT.CS.Vended
{
    [DisableAuditing]
    public class VendedAppService : CSAppServiceBase, IVendedAppService
    {
        private readonly IRepository<Attribute> _aRepository;
        
        public VendedAppService(IRepository<Attribute> aRepository)
        {
            _aRepository = aRepository;
        }

        public List<Attribute> GetAttributes()
        {
            var attributes = _aRepository.GetAllList().ToList();
            return attributes;
        }
    }
}

Any assistance would be appreciated.

You may want to take a look at the calendar component that is included with the Metronic template that ASP.NET Zero uses. You can see a sample of it here.

Thank you very much!

Hi,

My question is even more basic than that. How do I configure a newly created app to use the MPA backend, rather than the AngularJS backend. I think by default the app uses the AngularJS backend.

Sorry for the simple question, but how does one change the default backend app from AngularJS to MPA.

Thanks, MPM

Answer

Much appreciated.

Answer

Hi Halil.

In order to get the two DbContext's to work at all, I had already enabled DTC.

Security Settings

- Network DTC Access checked
      - Client and Administration
             - Allow Remote Clients checked
             - Allow Remote Administration unchecked
      - Transaction Manager Communication
             - Allow Inbound checked
             - Allow Outbound checked
             - Mutual Authentication Required is selected
     -  Enable XA Transactions unchecked
      - Enable SNA LU 6.2 Transactions checked

Thanks for checking into this.

Question

The app I am working on right now has two DbContext, and two controllers. The first controller (using the default DbContext) is logging to the audit log with no issue. The second controller (using the second DbContext) is not logging anything to the audit log.

Do you have any thoughts on possible causes?

I've created a unit test for creating a device object with a DeviceName, Site, and IsTraining bit. AutoMapper is throwing out the following error in the test. I'm not sure why my DTO and Domain object aren't able to map properly.

Result Message: AutoMapper.AutoMapperMappingException : Missing type map configuration or unsupported mapping.

Mapping types: DeviceEditDto -> Device MCMT.PatientCareReporting.Devices.Dto.DeviceEditDto -> MCMT.PatientCareReporting.Devices.Device

My test looks like so:

public class DeviceAppService_Create_Tests : DeviceAppServiceTestBase
    {
        [Fact]
        public async Task Should_Create_Device()
        {
            LoginAsHostAdmin();

            await CreateDeviceAndTestAsync("TESTDEVICE", "Rochester", false);
            await CreateDeviceAndTestAsync("R5001011", "Austin", true);
        }

        private async Task CreateDeviceAndTestAsync(string deviceName, string site, bool isTraining)
        {
            //Act
            await DeviceAppService.CreateOrUpdateDevice(
                new CreateOrUpdateDeviceInput
                {
                    Device = new DeviceEditDto
                    {
                        DeviceName = deviceName,
                        Site = site,
                        IsTraining = isTraining
                    }
                });

            //Assert
            UsingDbContext(async context =>
            {
                //Get created device
                var createdDevice = await context.Devices.FirstOrDefaultAsync(u => u.DeviceName == "TESTDEVICE");
                createdDevice.ShouldNotBe(null);

                //Check some properties
                createdDevice.Site.ShouldBe("Rochester");
                createdDevice.IsTraining.ShouldBe(false);
            });
        }
    }

My domain object is as follows:

[Table("rntDevice")]
    public class Device : FullAuditedEntity
    {
        public const int MaxDeviceNameLength = 10;
        public const int MaxSiteLength = 32;
        
        [Required]
        [MaxLength(MaxDeviceNameLength)]
        public virtual string DeviceName { get; set; }

        [Required]
        [MaxLength(MaxSiteLength)]
        public virtual string Site { get; set; }
 
        public virtual bool IsTraining { get; set; }
    }

and the DTO object looks like so:

public class DeviceEditDto : IValidate
    {
        /// <summary>
        /// Set null to create a new device. Set device's Id to update a device
        /// </summary>
        public long? Id { get; set; }

        [Required]
        [StringLength(Device.MaxDeviceNameLength)]
        public string DeviceName { get; set; }

        [Required]
        [StringLength(Device.MaxSiteLength)]
        public string Site { get; set; }

        public bool IsTraining { get; set; }
    }

Any thoughts I what I might have wired together incorrectly?

Showing 1 to 10 of 12 entries