"Not Found" Exception when trying to call UpdateAsync or InsertAsync - xamarin

I'm creating a pretty basic Azure Mobile App based on the TodoItem example, and i'm running into a weird issue. I can connect to the table controller and call ToEnumerableAsync (GET) without issue, but as soon as I call UpdateAsync or InsertAsync, I get a 404 (Not Found) response. I tried recreating the table controller, disabling authentication etc. to no avail.
Log stream on Azure sees the PATCH message and returns the 404. Not terribly helpful...
my DTO looks like this:
public class Patient : EntityData
{
public string PersonalHealthNumber{ get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public DateTime? DateOfBirth { get; set; }
}
and my client-side patient looks like this:
public class Patient
{
public string Id { get; set; }
public string PersonalHeathNumber { get; set; }
public string FirstName { get; set; }
public string MiddleName { get; set; }
public string LastName { get; set; }
public DateTime? DateOfBirth { get; set; }
[Version]
public string Version { get; set; }
}

Try derive your client model from that TableData base class and remove the 2 properties Id and Version from your client model because they are in the base class

Related

How to handle char property properly in Hotchocolate Graphql 12.0?

I am trying to implement filtering on Resource table which has MartialStatus of char property in DDL of database.Let my show you my approach first. In my program.cs file, i have the following:
using LIS.ResourcePlanningSystem.API;
using LIS.ResourcePlanningSystem.Data;
using Microsoft.EntityFrameworkCore;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddDbContext<RpsDbContext>(options => options.UseLazyLoadingProxies().UseNpgsql(builder.Configuration.GetConnectionString("RPSDbContext")));
builder.Services.AddGraphQLServer().
RegisterDbContext<RpsDbContext>().
AddQueryType<Query>().
AddProjections().
AddFiltering().
AddSorting().
BindRuntimeType<char, StringType>().
AddTypeConverter<char, string>(from => from.ToString()).
AddTypeConverter<string, char>(from => from.ToCharArray()[0]);
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.MapGraphQL("/graphql");
app.Run();
Here is my a model Register.cs which has "MaritalStatus" char property.
public class Resource
{
public int Id { get; set; }
public string? FirstName { get; set; }
public string? MiddleName { get; set; }
public string? LastName { get; set; }
public string? FullName { get; set; }
public char? MaritalStatus { get; set; }
public virtual Gender? Gender { get; set; }
public virtual Education? Education { get; set; }
public int? InstitutionId { get; set; }
public string? PerStreet { get; set; }
public DateTime? OfficeJoinDt { get; set; }
public virtual Grade? Grade { get; set; }
public int? PositionId { get; set; }
public virtual Department? Department { get; set; }
public virtual ClientType? ClientType{ get; set; }
public int? ExpOut { get; set; }
public string? ResignedFlag { get; set; }
public string? Email { get; set; }
public virtual BloodGroup? BloodGroup { get; set; }
public virtual ResignedRemarks? ResignedRemark { get; set; }
public virtual Source? Source { get; set; }
}
Now, the program runs just fine until i add [UseFiltering] on the Resource table in query.cs file.
[UseFiltering]
[UseSorting]
public IQueryable<Resource>? GetResources(RpsDbContext context) => context.Resources;
The error i am getting is this:
HotChocolate.SchemaException: For more details look at the `Errors` property.
1. For more details look at the `Errors` property.
1. The type of the member MaritalStatus of the declaring type Resource is unknown
If i remove the [UseFiltering] [UseSorting], the program works fine. I think the problem is related to filtering on resource table. Filtering also work fine on all the other tables which doesn't have char property in its schema definition. Someone has opened a bug issue on github [here] . Tried to solve reading this issue but no luck. Could somebody please tell me how can i get around this problem?

Automapper Many to Many Mapping Including Joining Table Data

I am developing an ASP.Net Core Web API using EF Core Code First (C#) and SQL Server.
I have a fairly simple scenario which I just cannot figure out. I have a Form entity and a Site entity. Each Form can have many Sites and each Site can be in many Forms. To enable this I have a SiteForm joining table. For each Site associated with a Form there is a Leaving Date field. So my SiteForm class looks like this:
public class SiteForm
{
public Guid SiteId { get; set; }
public Site Site{ get; set; }
public Guid FormId { get; set; }
public Form Form{ get; set; }
public DateTime? LeavingDate { get; set; }
}
My Form's Data Transfer Object (FormDto) is as follows:
public class FormDto
{
public Guid Id { get; set; }
...
public ICollection<LinkedSiteDto> LinkedSites { get; set; }
= new List<LinkedSiteDto>();
}
And my LinkedSiteDto is like this:
public class LinkedSiteDto
{
public Guid Id { get; set; }
public string Name { get; set; }
public string Ident { get; set; }
public DateTime? LeavingDate { get; set; }
}
Having populated the database I can get the Sites for each Form using the following mapping:
CreateMap<Form, FormDto>()
.ForMember(dto => dto.LinkedSites, opt => opt.MapFrom(
form => form.SiteForms.Select(sf => sf.Site).ToList()));
I just cannot figure out how I would include the LeavingDate value from each joining table entry? Any suggestions would be very gratefully received.

How to Retrieve Systems Properties from Azure Mobile Services .Net Backend

How can I retrieve the System Properties of "__createdAT" and "__updatedAT" from an Azure Mobile Service Table (.Net Backend). I see that these values exist on the Azure SQL Server.
This is my backing Model Class
public class Customer : EntityData
{
public string CustomerName { get; set; }
public string CustomerEmail { get; set; }
public string PhoneNumber { get; set; }
public string CardUid { get; set; }
}
And I can confirm that the columns are created at the Azure Mobile Services backing SQL Backend
And here is my Xamarin Android model class
public class Customer
{
public string id { get; set; }
[JsonProperty(PropertyName = "customerName")]
public string CustomerName { get; set; }
[JsonProperty(PropertyName = "customerEmail")]
public string CustomerEmail { get; set; }
[JsonProperty(PropertyName = "phoneNumber")]
public string PhoneNumber { get; set; }
[JsonProperty(PropertyName = "cardUid")]
public string CardUid { get; set; }
[CreatedAt]
public DateTime EnrollmentDate { get; set; }
[UpdatedAt]
public DateTime LastTransactionDate { get; set; }
}
However, this does not return the values, here is what it returns to the Xamarin.Android client
Even the web Try it out does not return the CreatedAT and UpdatedAT column, how can I return these columns to the clients.
Thanks
In the client SDK you need to specify that you want the system properties returned (they are not by default).
In C# you would do something like this:
customerTable = myAzClient.GetTable<Customer>;
customerTable.SystemProperties = MobileServiceSystemProperties.CreatedAt | MobileServiceSystemProperties.UpdatedAt;
var customers = await customerTable.ReadAsync();
You can see more in Carlos' blog post
Try renaming you CreatedAt and UpdatedAt Properies in your client side DTO classes.
public class Customer
{
....
[CreatedAt]
public DateTime CreatedAt{ get; set; }
[UpdatedAt]
public DateTime UpdatedAt{ get; set; }
}
This worked for me the last time

scaffolding seems not to work properly

I created a new asp.net MVC3 application (internet application), and then I added a new model with 3 classes:
public class BizCard
{
[Required]
public string BizCardID { get; set; }
[Required]
public string Name { get; set; }
public string Address { get; set; }
public List<string> PhoneNumbers { get; set; }
[Required]
[DataType(DataType.EmailAddress)]
public string Email { get; set; }
public BizType type { get; set; }
public List<BizService> OfferedServices { get; set; }
public string Description { get; set; }
}
public class BizType
{
public int BizTypeID { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public double Price { get; set; }
}
public class BizService
{
public int BizServiceID { get; set; }
public List<BizType> AllowedBizTypes { get; set; }
public string Name { get; set; }
}
After that, I created a new controller, using the template "Controller with read/write actions and views using entity framework", I set the Model class to be "BizCard" and the data context class to be a new class which is called "BizDB". I was expecting to get a new class named BizDB that inherits from DbContext and includes 3 instances of DbSet:
DbSet<BizCard>, DbSet<BizType>, DbSet<BizService>.
In spite of that, I get the class with only one:
DbSet<BizCard>.
Am I missing something?
You are doing this using EF Code First approach.
1. So, you have to create a context class which should inherit DbContext containing required models as DbSet
2. Build the solution. Otherwise it will not be displayed at controller creation
Then you can create the controller using necessary model and its dbcontext.

ASP.NET MVC 3 Login page as database

I want to make Login page by using LINQ.
Can I use [Authorize] on controller? or How can I make authorization through database?
I want to make custom login page without web site administration tool because it does not provide more details.
Could you help me? I am really beginner MVC 3.
Please give your hands. Thanks.
Here is my Customer table. Can I use this table for authorization?
Thanks
public class Customer
{
[Key] public int customerId { get; set; }
public Boolean admin { get; set; }
public String userName { get; set; }
public String password { get; set; }
public String firstName { get; set; }
public String lastName { get; set; }
public String company { get; set; }
public String address { get; set; }
public String postCode { get; set; }
public String email { get; set; }
public String phone { get; set; }
public String sortCode { get; set; }
public String accountNo { get; set; }
public String cardHolder { get; set; }
public String cardNo { get; set; }
public int securityCode { get; set; }
}
Yes you can use [Authorize] on your controller, or on individual actions to force the user to be authorized in order to use them.
As you say you are new to MVC, I'd suggest that you have a look at the tutorials on the ASP.Net MVC web site. I believe The MVC Music Store example show you how to implement authorization etc.
You can also have a look at the Nerd Dinner project, which is a great way to get started and to have something that is working to play around with and to learn from.

Resources