public UserReportViewModel(string id, DateTime timeFrom, DateTime timeTo) { TimeFrom = timeFrom; TimeTo = timeTo; using (var db = new AssetHubContext()) { var user = db.Users.Find(id); Name = $"{user.FirstName} {user.LastName}"; Position = user.UserPositionId.HasValue ? user.UserPosition.Name : "Unknown"; Room = user.RoomId.HasValue ? user.Room.Name : "Unknown"; Loans = new List <Tuple <string, string, DateTime, DateTime> >(); foreach (var l in user.Loans) { var x = l.TimeFrom >= TimeFrom && l.TimeFrom <= TimeTo; var y = l.TimeTo >= TimeFrom && l.TimeTo <= TimeTo; if (!(x || y)) { continue; } Loans.Add(new Tuple <string, string, DateTime, DateTime>(l.Asset.Name, l.Asset.SerialNumber, l.TimeFrom, l.TimeTo)); } } }
// GET: ViewUser public ActionResult ViewUser(string id) { var currentId = User.Identity.GetUserId(); var user = new AssetHubContext().Users.Find(currentId); return(View(new ViewUserViewModel(id, user.IsAdmin, id == currentId))); }
public static string ValidateEmail(string id, string email) { if (string.IsNullOrWhiteSpace(email)) { return(EMAIL_REQUIRED); } try { var mail = new System.Net.Mail.MailAddress(email); using (var db = new AssetHubContext()) { var existing = (from u in db.Users where u.Email.ToLower().Contains(email.ToLower()) && u.Id != id select u).Count(); return(existing > 0 ? DUPLICATE_EMAIL : null); } } catch { return(INVALID_EMAIL); } }
public ActionResult Index() { var id = User.Identity.GetUserId(); var user = new AssetHubContext().Users.Find(id); if (user == null) { return(RedirectToAction("Login", "Account")); } return(View(new IndexViewModel(user.Id))); }
public ActionResult Login() { var id = User.Identity.GetUserId(); var user = new AssetHubContext().Users.Find(id); if (user != null) { return(RedirectToAction("Index", "Home")); } return(View()); }
public ViewAssetModelViewModel(int id) { using (var db = new AssetHubContext()) { var assetModel = db.AssetModels.Find(id); Id = assetModel.Id; Name = assetModel.Name; Category = assetModel.AssetModelCategory; Properties = assetModel.Properties.ToList(); Assets = assetModel.Assets.ToList(); } }
public void Execute(IJobExecutionContext context) { try { using (var db = new AssetHubContext()) { var x = (from a in db.Assets join l in db.Loans on a.Id equals l.AssetId where DateTime.Now >= l.TimeFrom && DateTime.Now <= l.TimeTo && l.RoomId != a.Locations.Where(al => al.TimeTo == null).Select(al => al.RoomId).FirstOrDefault() select new { AssetId = a.Id, RoomId = l.RoomId }).ToList(); foreach (var y in x) { var currentLocation = (from l in db.AssetLocations where l.TimeTo == null && l.AssetId == y.AssetId select l).FirstOrDefault(); if (currentLocation != null) { currentLocation.TimeTo = DateTime.Now; } db.AssetLocations.Add(new AssetLocation { AssetId = y.AssetId, RoomId = y.RoomId, TimeFrom = DateTime.Now, TimeTo = null, }); } db.SaveChanges(); } } catch (Exception e) { ; } }
public static string ValidateAssetAvailabilty(int assetId, DateTime timeFrom, DateTime timeTo) { using (var db = new AssetHubContext()) { var existing = (from l in db.Loans where l.AssetId == assetId select l).ToList(); foreach (var l in existing) { var x = timeFrom > l.TimeFrom && timeFrom < l.TimeTo; var y = timeTo > l.TimeFrom && timeTo < l.TimeTo; if (x || y) { return(LOAN_EXISTS); } } return(null); } }
public static string ValidateName(int?id, string name) { using (var db = new AssetHubContext()) { if (string.IsNullOrWhiteSpace(name)) { return(NAME_REQUIRED); } else { var existing = (from c in db.AssetModelCategories where c.Name.Equals(name, StringComparison.CurrentCultureIgnoreCase) && c.Id != id select c).ToList(); if (existing.Count != 0) { return(NAME_EXISTS); } } } return(null); }
public static string ValidateName(int?id, string name, int categoryId) { using (var db = new AssetHubContext()) { if (string.IsNullOrWhiteSpace(name)) { return(NAME_REQUIRED); } var existing = (from c in db.AssetModelCategories join m in db.AssetModels on c.Id equals m.AssetModelCategoryId where m.Name.Equals(name, StringComparison.InvariantCultureIgnoreCase) && m.AssetModelCategoryId != categoryId select m).Count(); if (existing != 0) { return(NAME_EXISTS); } } return(null); }