Table already had Delete column for soft delete from web application.
Same table I have pointed to azure mobile services/app.
Also created DeleteMS column for mobile services and used auto mapper in WebApiConfig.cs.
While creating DTO, I rename old Delete column to IsDelete and kept as it is EntityData-Delete property.
Contactdto
public class Contactdto : EntityData
{
public int contact_id { get; set; }
public bool IsDeleted { get; set; }
//public bool DeletedMS { get; set; } //manually added column
}
WebApiConfig.cs
cfg.CreateMap<tblcontact, Contactdto>()
.ForMember(dto => dto.IsDeleted, map => map.MapFrom(tbl => tbl.deleted));
cfg.CreateMap<Contactdto, tblcontact>()
.ForMember(tbl => tbl.DeletedMS, map => map.MapFrom(dto => dto.Deleted));
Is this a right approach? or shall I use same column already we had?
Once record is deleted from mobile app. Will it affect in Web Application after sync service run?
Please help.
If you already implemented soft delete in your web app, it's easiest to just use that exact same column in your Mobile App backend. The only way a record will be marked as deleted is when there is a DELETE call, either through the /tables endpoint or the mobile client.
Also, make sure you are using Mobile Apps, as that is the latest version of the service. See What are Mobile Apps.
Related
Currently, I have EF working perfectly fine with asp net core identity. My web app allows users to login in 2 ways: using their local account and using their azure active directory account. However, only the allowed azure directory accounts are allowed to log in. Therefore, I need to create another table to hold those accounts to cross check when they log in.
If you want to create a new table for the Identity project, I suggest you could try to modify the identity EF's dbcontext with the new create model class.
More details, you could refer to below codes:
public class UserRelationship
{
public int UserId { get; set; }
}
Modify the ApplicationDbContext :
public class ApplicationDbContext : IdentityDbContext
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
: base(options)
{
}
public DbSet<UserRelationship> UserRelationships { get; set; }
}
Then you could enable the migration and update the database like this article shows.
I am using Azure mobile apps with .NET backend and Xamarin as client app.
I have multiple tables as follows:
Badges - where badge description is stored
Achievmentgroups - one group can have multiple badges .e.g badge x level 1 ,badge x level 2 , badge y level 1 ,badge y level 2... etc
CustomerAchievments - where the progress of each badge is stored for each user
Badges and achievmentsgroups are linked together with foreign key lets name it achievmentGroupId.
CustomerAchievments and Badges are linked together with foreign key lets name it BadgeId
In my client side, I would like to create one object from these three tables.
currently what I am doing is getting each table separately and i want to utilize object oriented programming more.
As of what I understand from your question The easiest way of doing this would be bunching them together so what your final class would look like is as shown below:
public class Customer
{
public Badges Badges { get; set; }
public Achievmentgroups Achievmentgroups { get; set; }
public CustomerAchievments CustomerAchievments { get; set; }
}
In this way, your .Net backend can send just one class and that can be used to get all your data individually!
a solution with an example here :
https://blogs.msdn.microsoft.com/azuremobile/2014/05/27/retrieving-data-from-1n-relationship-using-net-backend-azure-mobile-services/
I am using MVC with Entity framework.
I have a Client requirement that client want to set default period for all the context table. When he set some date range into the user setting page it saves the detail to the sql table. When the app runs application all the data from table will come for that particular period.
I want to apply this filter in my context file.
Here is my context file and suppose i got the date here.
public class MyContext : DbContext
{
public DbSet<Contact> Contacts { get; set; }
public DbSet<Contact_phone> Contact_phones{ get; set; }
}
How i achieve this.
Thanks
I'm hoping this is a simple question. I've created an Azure Mobile Apps project based upon the sample ToDo project, adding my own tables/data objects. The problem I'm having is adding/POSTing records to a table that has a foreign key relationship to another. The following is my Employee table data object:
public class Employee : EntityData
{
public string Name { get; set; }
public string EmailAddress { get; set; }
public bool IsActive { get; set; }
public string EmployeeTypeId { get; set; }
public virtual EmployeeType EmployeeType { get; set; }
}
...and this is my EmployeeType data object:
public class EmployeeType : EntityData
{
public string EmpType { get; set; }
public bool IsActive { get; set; }
}
The virtual EmployeeType property in the Employee class was necessary, I believe, to create the relationship with the EmployeeType table when using EF Code First to create the tables in the database. (At least, that's what I understand, and it worked) I am able to insert records from my Xamarin client app into the EmployeeType table using the InsertAsync method, but I receive a "Bad Request" 400 error when trying to insert into the Employee table.
I've looked around quite a bit for solutions, but everything refers to Azure Mobile Services and not Apps. If need be, I can update this question with my client side model classes (I'm on my PC now and don't have access to the Xamarin Studio project on my Mac). For reference, these classes are pretty much the same as the data objects - just each property is decorated with the JsonProperty attribute, except the virtual property outlined in the service. And for completeness, I did try adding that property to the client object and it still threw the "Bad Request" 400 error.
Thanks for any direction you can offer me.
Most likely, the problem is happening when trying to map the foreign key. Are you specifying all of the fields for employee type? I recommend that you do the following:
Use Fiddler or attach a delegating handler to your client to see what the outgoing request looks like. Update your comment with the JSON body. See https://github.com/Azure/azure-mobile-apps/wiki/Help,-my-app-isn't-working!#log-outgoing-requests-in-managed-client-xamarin-windows.
Attach a debugger to your server project. You can do this while running locally or after your solution is deployed to Azure, but you'll have better performance if you run locally. See https://github.com/Azure/azure-mobile-apps/wiki/Help,-my-app-isn't-working!#remote-debugging-net-server-sdk.
I suspect that the problem is that EmployeeType ends up being null in your deserialized object, and then Entity Framework rejects the DB insert.
Could you get more information from the bad request? Try adding this to the table controller
protected override void Initialize(HttpControllerContext controllerContext)
{
controllerContext.Configuration.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always;
}
I'm currently developing a side-project, which will consist of a Database, Web API, and then different Apps on top which consume the restful API.
I've started thinking about User accounts and how to make these secure. Currently, as a standard, I have the following model in the Data Layer:
public int Id { get; set; }
public string Username { get; set; }
public string Full_Name { get; set; }
public string Password { get; internal set; }
public string Salt { get; internal set; }
Now, obviously, when someone makes a request for /Users/{id}, the User associated with that Id is returned. However, I don't want to return the Password or Salt, so really don't want those to be part of the User model.
I have toyed with the idea of creating a different, internal-only model for UserDetails, and shipping the Password/Salt, etc off into that. However, I hit the snag of, when signing up to the service, how do I get a desired password from the user to the API?
There's probably a really simple implementation of what I want to do, but I can't think of one right now. Any help would be greatly appreciated!
You should use a special view model without the password property for this purpose. Then inside your API you will map between your data model and the view model and return the view model out from your Web API method. Same stands true for the Salt property as well.