I'm actually wrapping my head around the problem of time. I wish to allow the user to input data between Monday-Wednesday (Monday 00:00 to Wednesday 23:59) each week just once AND create a unique id that would represent each week.
I need this id later, so the user can't insert another piece of the same data until next week opening.
At first, I went for DateTime.Today but then realised that it doesn't prevent the user from inserting another piece of data the next (or the other) day.
Now I'm thinking of creating an action filter that would block out the user if he has already signed in data for the week and take it on the next Monday. I'd need a function that resets the flag on Monday 00:00 and raise flag on Thursday 00:00 (if user hasn't signed the data in) which atm seems a lot of time-control work (that's why I went for unique id 1st) and setting on/off the action filter (which I don't know if is really possible or how to do it).
I think that this is a bad road to follow meaning there could be another way to achieve my goal. Or there might even be some kind of solution already. That's why I ask you here, hoping for inspiration.
Thanks!
EDIT:
All of the above concerns raport_id as unique id.
db classes:
-raport
public class Raport
{
[DatabaseGenerated(DatabaseGeneratedOption.None)]
[Key]
public string raport_id { get; set; } //id raportu
public string userID { get; set; }
public DateTime creation_time { get; set; }
public int isMinus { get; set; }
public DateTime last_modyfication { get; set; }
public virtual ICollection<ThrashType> ThrashType { get; set; }
public virtual UserFrontInfo UserFrontInfo { get; set; }
}
-thrash type
public class ThrashType
{
[Key]
public int IdTrash { get; set; }
public string raport_id { get; set; }
public string ClassName { get; set; }
public bool isNegative { get; set; }
public int Quantity { get; set; }
public string Information { get; set; }
public virtual Raport Raport { get; set; }
}
creating raport_id:
var datePart = DateTime.Today.ToString().Replace(".", "").Replace(":","").Replace(" ","");
var namePart = User.Identity.Name.ToString();
var nameShort = namePart.Remove((namePart.Length)-13, 12);
newRaport.raport_id = datePart + nameShort;