コード例 #1
0
        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));
                }
            }
        }
コード例 #2
0
        // 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)));
        }
コード例 #3
0
            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);
                }
            }
コード例 #4
0
ファイル: HomeController.cs プロジェクト: chimex61/AssetHub
        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)));
        }
コード例 #5
0
        public ActionResult Login()
        {
            var id   = User.Identity.GetUserId();
            var user = new AssetHubContext().Users.Find(id);

            if (user != null)
            {
                return(RedirectToAction("Index", "Home"));
            }

            return(View());
        }
コード例 #6
0
        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();
            }
        }
コード例 #7
0
ファイル: Global.asax.cs プロジェクト: chimex61/AssetHub
            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)
                {
                    ;
                }
            }
コード例 #8
0
ファイル: Loan.cs プロジェクト: chimex61/AssetHub
            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);
                }
            }
コード例 #9
0
            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);
            }
コード例 #10
0
ファイル: AssetModel.cs プロジェクト: chimex61/AssetHub
            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);
            }