Change state of a property automaticly - asp.net-mvc-4

Hi guys im kinda new on asp.net mvc and im trying to do something that is kinda confusing me, i have a model called desafio(challenge) and that challenge has a avaliation property that should change after 24 hours my doubts is how can i do that where should i do that, should i create a new controller? i need something to control i already searched a lot and didnt find a proper way to do that i need some lights.
Do i need to create a function where i can change the state, but when should i call the function im a little bit confused.
Here is my challenge model
public class Desafio
{
public int DesafioId { get; set; }
public string TipoTrabalho { get; set; }
public virtual ApplicationUser User { get; set; }
public string ApplicationUserId { get; set; }
public string Descricao { get; set; }
public int TipoAvaliacaoId { get; set; }
public virtual TipoAvaliacao TipoAvaliacao { get; set; }
public decimal valor { get; set; }
public int Visualizacoes { get; set; }
public DateTime DataCriacao { get; set; }
public double lat { get; set; }
public double lon { get; set; }
public int IdSolucaoVencedora { get; set; }
public virtual ICollection<Tag> Tags { get; set; }
}
because my question is kinda confused i will explain it better, what i need here is to change my property value on my challenge(Desafio) depending on my system timer. For exemple when pass 4 hours it changes automaticly from "inAvaluation" to "Closed" there should be a way to implemente this but i didnt find anything yet

Related

Podio API - Groupings are missing from Views in C#

I am working with the Podio api in C# and "Groupings" is missing from the View and ViewCreateUpdateRequest model.
When I use the sandbox call the result includes the groupings. So I'm thinking it is missing in the C# nuget package. Is there another way to access groupings for both Get View and Update View?
Sadly they are not maintaining the SDK for C#, but you can download their code from https://github.com/podio/podio-dotnet and update the code yourself.
That's what I did, I change the following
ItemId data type from Integer to Long
Added Groupings in View (Below is my View looks like)
public class View
{
[JsonProperty("view_id")]
public string ViewId { get; set; }
[JsonProperty("name")]
public string Name { get; set; }
[JsonProperty("created_on")]
public DateTime CreatedOn { get; set; }
[JsonProperty("sort_by")]
public string SortBy { get; set; }
[JsonProperty("sort_desc")]
public string SortDesc { get; set; }
[JsonProperty("filters")]
public JArray Filters { get; set; }
[JsonProperty("fields")]
public JObject Fields { get; set; }
[JsonProperty("groupings")]
public JObject Groupings { get; set; }
[JsonProperty("created_by")]
public ByLine CreatedBy { get; set; }
[JsonProperty("layout")]
public string Layout { get; set; }
[JsonProperty("type")]
public string Type { get; set; }
[JsonProperty("rights")]
public string[] Rights { get; set; }
[JsonProperty("filter_id")]
public string FilterId { get; set; }
[JsonProperty("items")]
public int Items { get; set; }
}
Search for NuGet Package: Podio.Async by acl2

The new ASP.NET Core 3.0 Json serializer is leaving out data

I'm porting a web application to ASP.NET Core 3, and after a bit of a battle, I'm almost at the finish line. Everything seems to work, but all of a sudden my JSON data returned from the api is missing some levels.
It seems the options.JsonSerializerOptions.MaxDepth is default at 64 levels, so it can be that. Some other places where an option can be playing tricks on me?
This is the code (and a quickview of the value):
And this is the JSON I get in the browser:
So the ParticipantGroups property/collection is completely missing in the generated output.
Any ideas where this happens?
EDIT:
I've added a repo on Github that showcases the issue. Standard ASP.NET Core 3.0 solution, created from the template, with a change to the result returned from the Weatherforecast controller:
https://github.com/steentottrup/systemtextjsonissue
For now I've gone back to using Newtonsoft.Json, with the Microsoft.AspNetCore.Mvc.NewtonsoftJson package. Then when I have some time, I'll try finding out what the solution is, without Newtonsoft.Json.
The problem seems to be an error in the new version 3.0. At least it seems like an error to me.
It seems System.Text.Json will convert the class mentioned in the hierarchy, not the actual class. So if you are using an abstract class in the hierarchy, you're in trouble. The second I removed the base class, and used the actual class I'm returning, the problem goes away it seems.
So this doesn't work:
public class SurveyReportResult {
public Guid Id { get; set; }
public String Name { get; set; }
public Int32 MemberCount { get; set; }
public IEnumerable<OrganisationalUnit> OrganisationalUnits { get; set; }
}
public abstract class OrganisationalUnit {
public Guid Id { get; set; }
public String Name { get; set; }
public Int32 MemberCount { get; set; }
}
public class OrganisationalUnitWithParticipantGroups : OrganisationalUnit {
public IEnumerable<ParticipantGroup> ParticipantGroups { get; set; }
}
public class ParticipantGroup {
public Guid Id { get; set; }
public String Name { get; set; }
public Int32 MemberCount { get; set; }
}
This will only return the properties of the OrganisationalUnit class, not the additional property of the OrganisationalUnitWithParticipantGroups.
This works:
public class SurveyReportResult {
public Guid Id { get; set; }
public String Name { get; set; }
public Int32 MemberCount { get; set; }
public IEnumerable<OrganisationalUnitWithParticipantGroups> OrganisationalUnits { get; set; }
}
public class OrganisationalUnitWithParticipantGroups /*: OrganisationalUnit*/ {
public Guid Id { get; set; }
public String Name { get; set; }
public Int32 MemberCount { get; set; }
public IEnumerable<ParticipantGroup> ParticipantGroups { get; set; }
}
public class ParticipantGroup {
public Guid Id { get; set; }
public String Name { get; set; }
public Int32 MemberCount { get; set; }
}

When including other entities other lists are loaded too which leads into a recursion, how can i prevent this?

I have a big database in the background storing:
public partial class Phone
{
public string Imei { get; set; }
public int ColourId { get; set; }
public int StorageId { get; set; }
public int TypeId { get; set; }
public int ModelId { get; set; }
public int PurchasePrice { get; set; }
public DateTime? SaleDate { get; set; }
public DateTime? RentalStart { get; set; }
public DateTime? RentalFinish { get; set; }
public virtual Colour Colour { get; set; }
public virtual Storage Storage { get; set; }
public virtual Type Type { get; set; }
}
public partial class Storage
{
public Storage()
{
Phone = new HashSet<Phone>();
}
public int StorageId { get; set; }
public string Amount { get; set; }
public virtual ICollection<Phone> Phone { get; set; }
}
And I am requesting for the Phone Data like this in my WebAPI:
[HttpGet]
// GET: Phones
public async Task<IActionResult> Index()
{
var phoneCalculatorContext = _context.Phone.Include(p =>
p.Colour).Include(p => p.Storage).Include(p => p.Type);
return Ok(await phoneCalculatorContext.Take(10).ToListAsync());
}
I have posted the JSON Response here:
https://textuploader.com/1dtu2
As you can see in my response is storage included (as expected) but storage has a reference to my Phone Collection and this goes on and on and on (like an recursion)
Is it possible to not get the lists?
Because I dont need the lists I just need to get the amount of storage but not the pone list.
Sorry for the poor understanding of EF but I am pretty new to this.
If you don't need that an storage know in how many phones it's, you can remove the ICollection property.
other solution is mark the phones property in storage as this
[JsonIgnore]
public virtual ICollection<Phone> Phone { get; set; }
For disabling self reference serialize, you could try SerializerSettings.ReferenceLoopHandling like
services.AddMvc()
.AddJsonOptions(opt => {
opt.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;
}).SetCompatibilityVersion(CompatibilityVersion.Version_2_2);

Using Complex DataType in EF CodeFirst

this is my Model :
public class Course
{
public int Id { get; set; }
public string Title { get; set; }
public string Institute { get; set; }
public string Instructor { get; set; }
public string Duration { get; set; }
public Level Level { get; set; }
public Format Format { get; set; }
public DateTime Released { get; set; }
public string FileSize { get; set; }
public string Desciption { get; set; }
}
public enum Level
{
Beginner,
Intermediate,
Advanced
}
public enum Format
{
Avi,
Hd,
FullHd
}
public class CourseDb:DbContext
{
public DbSet<Course> Courses { get; set; }
}
when I want to Create my new Controller with Scoffolding Using EF Template,
It's not create both Level and Format fields while I am using EF5
what's my problem?
Thanks in your advise
Enum types are currently not supported when scaffolding, which is most likely why the fields are not created.
My advice would be to use a helper method such as : Working with enums in ASP.NET MVC 3
and code it manually.
Update:
Looks like there is ticket logged for the support it here: http://mvcscaffolding.codeplex.com/workitem/10

How to add a couple of million documents to RavenDB - Embedded

I have installed the latest embedded binaries from NuGet and am using this code to store a 'product' poco. After a bit, the process dies with an OutOfMemoryException. Is storing this much data out of scope for Raven?
Thank you.
Stephen
var store = new EmbeddableDocumentStore { DataDirectory = #"C:\temp\ravendata", UseEmbeddedHttpServer = true };
store.Initialize();
using (var session = store.OpenSession())
{
foreach (var item in Parsers.GetProducts().ToList())
{
session.Store(item);
}
session.SaveChanges();
//var rdbList = session.Query<Product>().ToList();
}
[Serializable]
public class Product
{
public decimal ProductId { get; set; }
public string ItemNum { get; set; }
public string ProductName { get; set; }
public string BrandName { get; set; }
public string UOM { get; set; }
public string AveWeight { get; set; }
public string CasePack { get; set; }
public string PackageRemarks { get; set; }
public decimal Price { get; set; }
public string SupplierName { get; set; }
public string Url { get; set; }
public bool IsSpecialOrderItem { get; set; }
public bool IsSpecialPriceItem { get; set; }
public bool IsRebateItem { get; set; }
public bool IsTieredPricingItem { get; set; }
public bool IsOfflineSupplierItem { get; set; }
public string Catalog { get; set; }
public decimal CatalogId { get; set; }
public decimal CategoryId { get; set; }
public decimal PriceGroupId { get; set; }
public decimal OffineSupplierId { get; set; }
public string ManufactureName { get; set; }
public string ManufactureNum { get; set; }
public string Upc { get; set; }
public string Info { get; set; }
public string INFO2 { get; set; }
}
How big of a batch are you doing? It looks like people have success with 256 batch sizes. Seems like much more causes timeouts and memory exceptions.
*EDIT: It sounds like it is also recommended to make a new session per batch so as to not keep the session open too long which can cause timeout errors.
No, RavenDB is perfectly fine with this amount of data. Unless you don't RunInMemory an EmbeddedDocumentStore is pretty much the same as a standalone server, just without the http overhead and direct access to the database from the client.
Given your code, you want to make sure that you store your documents in batches, e.g. 1024 for each session. Another thing you want to make sure is, that your GetProducts() method returns an IEnumerable and yields the items in a proper ETL way of doing things.