Base solution for your next web application

Activities of "vnetonline"

Hi.

I have a simple class

public class Car : Entity{

public virtual DateTime AddDate {get;set;} // retrieved from the Session object public virtual DateTime UpdateDate { get;set;} public virtual string UserName{ get; set; } }

I am using the AsyncCrud Interface. However I want to factor out these properties in a base object and set them everytime the user creates or updates an entity. so that these are updated for all objects automatically. I cannot use the built in AuditedEntity class since this is a database first context.

I cannot seem to do this at the Core layer or the entity framework layer (plus session object is available on at the services layer). Can you please specify how this is achieved. I also do not want to pass this information in the DTO objects. It should be set by default whenever a new object is created or updated. Your help will be greatly appreciated.

Regards

Here is my latest code for person entity in the core project

[Table("Person")]
    public class Person : Entity<string>
    {

        //[Key]
        //public virtual string Pre_ID { get; set; }

        [Column("Per_ID")]
        [DatabaseGenerated(DatabaseGeneratedOption.None)]
        public override string Id { get; set; } 

        public virtual string FirstName { get; set; }

        public virtual string LastName { get; set; }

        public virtual string Salutation { get; set; }

        //[NotMapped]
        //public string Id
        //{
        //    get
        //    {
        //        return Pre_ID;
        //    }

        //    set
        //    {
        //        Pre_ID = value;
        //    }
        //}

        public override bool IsTransient()
        {
            return false;
        }
    }

When I try that the Id is written as an empty string, can you please give me sample code how you would do it ??

I have resolved this by looking in the logs file located in App_Data\Logs directory, It turns out i was spelling the Pre_ID wrong where it should be Per_ID.

So Get and GetAll AsyncCrudAppService methods now are working.

My next problem is to do with Create and Update, the existing DB has the Per_ID column set to required and needs to be populated with a unique identifier made out of a GUID with out dashes.

Is there a way i can generate this in my CreatePersonInput. here is what i am trying but i get a Sustem.Overflow error.

[AutoMapTo(typeof(Person))]
    public class CreatePersonInput : IEntityDto<string>
    {

        //public string Id { get; set; }

        public string FirstName { get; set; }

        public string LastName { get; set; }

        public string Salutation { get; set; }

        public string Id
        {
            get
            {
                return Id;
            }

            set
            {
                if (value == "" )
                {
                    Id = Guid.NewGuid().ToString("N").ToUpper();
                }
            }
        }
    }

Dear Support

I am still have issues comminicating with a DB on another server here is what I have done

Created a ErpDbContext as follows and defied "Erp" connection string in web.config

public class ErpDbContext : AbpDbContext
    {
        /* Define an IDbSet for each entity of the application */

        //VB - 2017-01-11 - Erp tables
        public virtual IDbSet<Person> Persons { get; set; }


        /* Setting "Default" to base class helps us when working migration commands on Package Manager Console.
         * But it may cause problems when working Migrate.exe of EF. ABP works either way.         * 
         */
        public ErpDbContext()
            : base("Erp")
        {
            
        }


    }

Created a Person Entity in Core project

[Table("Person")]
    public class Person : IEntity<string>
    {

        [Key]
        public virtual string Pre_ID { get; set; }

        public virtual string FirstName { get; set; }

        public virtual string LastName { get; set; }

        public virtual string Salutation { get; set; }

        [NotMapped]
        public string Id
        {
            get
            {
                return Pre_ID;
            }

            set
            {
                Pre_ID = value;
            }
        }

        public bool IsTransient()
        {
            return false;
        }
    }

Created a PersonDto in Application project

[AutoMap(typeof(Person))]
    public class PersonDto : IEntityDto<string>
    {

        public virtual string Pre_ID { get; set; }

        public string FirstName { get; set; }

        public string LastName { get; set; }

        public string Salutation { get; set; }

        public string Id
        {
            get
            {
                return Pre_ID;
            }

            set
            {
                Pre_ID = value;
            }
        }
    }

Created IPersonAppService as follows

public interface IPersonAppService : IAsyncCrudAppService<PersonDto, string, GetAllPersonsInput, CreatePersonInput, UpdatePersonInput>
    {

        Task<ListResultDto<PersonDto>> GetAllPersons();

    }

Created PersonAppService as follows

public class PersonAppService : AsyncCrudAppService<Person, PersonDto, string, GetAllPersonsInput, CreatePersonInput, UpdatePersonInput>,
        IPersonAppService
    {

        public PersonAppService(IRepository<Person, string> personRepository)
            :base(personRepository)
        {

        }

        public async Task<ListResultDto<PersonDto>> GetAllPersons()
        {
            var personList = await Repository.GetAllListAsync();

            return new ListResultDto<PersonDto>(personList.MapTo<List<PersonDto>>());
        }


    }

When I go to Swagger UI I can see the CRUD

app/person Show/Hide List Operations Expand Operations
POST /api/services/app/person/GetAllPersons
POST /api/services/app/person/Get
POST /api/services/app/person/GetAll
POST /api/services/app/person/Create
POST /api/services/app/person/Update
POST /api/services/app/person/Delete

When I try to execute GetAll call I am getting the following error

{
  "result": null,
  "targetUrl": null,
  "success": false,
  "error": {
    "code": 0,
    "message": "An internal error occurred during your request!",
    "details": null,
    "validationErrors": null
  },
  "unAuthorizedRequest": false,
  "__abp": true
}

Thanks in advance for your help

Thanks for your reply.I have managed to setup all the plumbing.

The table in the DB I want to read/write from doesn't have a primary key named Id it has a primary key named Pre_ID and it uses a GUID without the dashes for its Key, I am also can to use the AsyncCrudAppService so that we can expose CRUD via WepAPI.

Can you please let me know how I can achieve this??

Thanks and Kind Regards Vineet Belani

Dear Support

I have a requirement to read/write data to another database, however i don't want to run migration on that database ... is that possible.

I have seen a sample project which shows you how to talk to multiple databases however migrations are enabled on both databases.

Thanks in advance for your help

Dear Support

I am wanting to use the CrudAppService and/or AsyncCrudAppService and it works great when mapped to one Table/Entity which has no relationships with other tables/entities.

However, when I have a table which has a relationship with another table/entity i.e. "ICollection<Phone> Phones" part of the Person Class I am unable to use the update method to update the phones collection in the Person Object.

Can you please let me know if this AppService can update multiple tables/entities which have a relationship??

Thanks and KInd Regards vnetonline

I am trying to use the JWT Token Authentication by using postman to request a token by going to the following address

<a class="postlink" href="http://localhost:6240/jwt-token/authenticate">http://localhost:6240/jwt-token/authenticate</a>

I am getting a Status 200 OK, however i am having the following response

<!DOCTYPE html>

    
        
        <html lang="en" dir=>
            
            <head>
                <meta charset="utf-8" />
                <title>AppConnect</title>
                <meta http-equiv="X-UA-Compatible" content="IE=edge">
                <meta content="width=device-width, initial-scale=1.0" name="viewport" />
                <meta http-equiv="Content-type" content="text/html; charset=utf-8">
                <meta content="AppConnect" name="description" />
                <meta content="AppConnect" name="keywords">
                <meta content="AppConnect" name="author" />
                <link rel="shortcut icon" href="/favicon.ico" />
                <link href="/Content/fonts-open-sans.css" rel="stylesheet" type="text/css" />
                <link rel="stylesheet" type="text/css" href="/Content/font-awesome.min.css?v=636175753326229755" />
                <link rel="stylesheet" type="text/css" href="/libs/simple-line-icons/simple-line-icons.min.css?v=636175753462769460" />
                <link rel="stylesheet" type="text/css" href="/libs/bootstrap/css/bootstrap.min.css?v=636175753350929457" />
                <link rel="stylesheet" type="text/css" href="/libs/jquery-uniform/css/uniform.default.css?v=636175753424449461" />
                <link rel="stylesheet" type="text/css" href="/metronic/assets/global/css/components-md.css?v=636175753516409495" />
                <link rel="stylesheet" type="text/css" href="/metronic/assets/global/css/plugins-md.css?v=636175753518069477" />
                <link rel="stylesheet" type="text/css" href="/Views/Error/_Layout.css?v=636175753704869461" />
                <script type="text/javascript">
        
        var abp = abp || {}; abp.appPath = '/';
  </script>
            </head>
            <body class="page-404-full-page">
                <div class="row">
                    <div class="col-md-12 page-404">
                        <div class="number font-red"> 404 </div>
                        <div class="details">
                            <h3>Oops! You&#39;re lost.</h3>
                            <p>
        We can not find the page you&#39;re looking for.
                                <br>
                                <a href="/" class="link">Home page</a>.
                            </p>
                        </div>
                    </div>
                </div>
                
                <script src="/libs/jquery/jquery.min.js?v=636175753388689445" type="text/javascript"></script>
                <script src="/libs/bootstrap/js/bootstrap.min.js?v=636175753352659830" type="text/javascript"></script>
                <script src="/libs/jquery-blockui/jquery.blockui.min.js?v=636175753389339473" type="text/javascript"></script>
                <script src="/libs/jquery-uniform/jquery.uniform.min.js?v=636175753423909460" type="text/javascript"></script>
                <script src="/libs/jquery-cookie/jquery.cookie.min.js?v=636175753389519557" type="text/javascript"></script>
                <script type="text/javascript">
    abp.localization.defaultSourceName = 'AppConnect';
  </script>
                
                <script src="/AbpScripts/GetScripts?v=636190858995785233" type="text/javascript"></script>
                <script src="/libs/jquery-validation/js/jquery.validate.min.js?v=636175753426729463" type="text/javascript"></script>
                <script src="/libs/jquery-validation/js/localization/_messages_empty.js?v=636175753445940001" type="text/javascript"></script>
                <script src="/metronic/assets/global/scripts/app.js?v=636175753556739463" type="text/javascript"></script>
                <script type="text/javascript">
    App.setAssetsPath(abp.appPath + 'metronic/assets/');
  </script>
                <script src="/Common/Scripts/appUserNotificationHelper.js"></script>
                <script src="/Common/Scripts/consts.js"></script>
                <script src="/Common/Scripts/helpers.js"></script>
                <script src="/Common/Scripts/jquery-custom.js"></script>
                <script src="/Common/Scripts/jquery-validation-custom.js"></script>
                <script src="/Common/Scripts/librarySettings.js"></script>
                <script src="/Common/Scripts/ModalManager.js"></script>
                <script src="/Common/Scripts/passwordComplexityHelper.js"></script>
                <script src="/Common/Scripts/utils.js"></script>
                <script src="/Common/Scripts/Chat/chat.js"></script>
                <script src="/Common/Scripts/Chat/chat.signalr.js"></script>
                <script src="/Common/Scripts/LocalStorage/localStorage.js"></script>
                <script src="/Common/Scripts/LocalStorage/localStorage.localForage.js"></script>
                <script src="/metronic/assets/admin/layout/scripts/layout.js?v=636175753494969559" type="text/javascript"></script>
                <script>
    jQuery(document).ready(function () {
      if (CurrentPage) {
        CurrentPage.init();
      }
    });
  </script>
                
                <script type="application/json" id="__browserLink_initializationData">
    {"appName":"Chrome","requestId":"c80ccfa8caaf49bd9489d156587d9201"}
</script>
                <script type="text/javascript" src="http://localhost:1853/fc4f53901f894a9daa652325c09bfb01/browserLink" async="async"></script>
                


            </body>
        </html>

do i have to enable JWT Token based Authentication, according to the following documentation i have everything setup fine

<a class="postlink" href="https://aspnetzero.com/Documents/Development-Guide-Core#authentication">https://aspnetzero.com/Documents/Develo ... entication</a>

Will the Angular2 UI work with the ASP.NET 4.6.x SPA, or only ASP.NET Core?

Showing 31 to 40 of 57 entries