As the title says, im trying to compare the stamped in datetime and stamped out datetime.
I have a flex variable which shall get the value of the difference between those two dates in a workday (8h).
"If I stamp in 08:00 and stamp out 17:00, my flex shall be +1(h)"
Model:
public class FlexModel
{
public List<User> Users { get; set; }
public List<Stamping> Stampings { get; set; }
public decimal FlexTime { get; set; }
}
public partial class Stamping
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
[Required]
public int UserId { get; set; }
[Required]
[DataType(DataType.DateTime)]
public DateTime Timestamp { get; set; }
[Required]
[StringLength(3)]
public string StampingType { get; set; }
public virtual User User { get; set; }
}
View:
@Html.LabelFor(model => model.FlexTime, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DisplayFor(model => model.FlexTime, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.FlexTime, "", new { @class = "text-danger" })
</div>
Controller:
public ActionResult Info()
{
var flexModel = new FlexModel();
var userId = (int)Session["userId"];
var user = _db.Users.Find(userId);
var stampIn = _db.Stampings
.Where(i => i.StampingType == "in")
.Where(i => i.User == user)
.ToList();
var stampOut = _db.Stampings
.Where(i => i.StampingType == "out")
.Where(i => i.User == user)
.ToList();
var workDay = 8;
if (stampIn.Count == 0)
{
return View();
}
foreach (var itemIn in stampIn)
{
//Dont know what to do here
}
foreach (var itemOut in stampOut)
{
//Dont know what to do here either
}
return View();
}
Please help.
TimeOutandTimeInboth ifTimeOutis null andTimeInnot null isTimeInif nboth then it isTimeOut