正如標題所說,即時通訊嘗試比較加蓋日期時間和加蓋日期時間。比較C#中的兩個列表ASP.NET MVC LINQ實體框架
我有一個彈性變量,它應該得到這兩個日期之間的差異值在工作日(8小時)。
「如果我在08:00郵票並加蓋了17:00,我的Flex應+1(H)」
型號:
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; }
}
查看:
@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>
控制器:
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();
}
請幫忙。
顯示衝壓類定義 – 2014-10-03 12:54:54
我剛剛編輯了!請看看... – Qvadriologic 2014-10-03 12:57:54
你的類的實現對我來說看起來不錯如果TimeOut是null,TimeIn'和TimeIn'兩者都會加入'TimeIn'非null是'TimeIn'如果nboth那麼它是' TimeOut' – 2014-10-03 13:00:06