Esempio n. 1
0
        public void DeleteApp(int appID)
        {
            using (CanIUpdateEFDB db = new CanIUpdateEFDB())
            {
                App app = db.Apps.Where(a => a.AppId == appID).FirstOrDefault();
                if (app == null)
                {
                    throw new Exception("App to delete not found. [appID: " + appID.ToString() + "]");
                }

                db.Apps.Remove(app);
                db.SaveChanges();
            }
        }
Esempio n. 2
0
        public void DeleteOS(int osID)
        {
            using (CanIUpdateEFDB db = new CanIUpdateEFDB())
            {
                OS os = db.OSs.Where(o => o.OSId == osID).FirstOrDefault();
                if (os == null)
                {
                    Utils.Log(new Logger("SiteData_OSs", "DeleteOS(" + osID.ToString() + ")", "OS to delete not found.", 42, LogType.ERROR));
                    throw new Exception("OS to delete not found. [osID: " + osID.ToString() + "]");
                }

                db.OSs.Remove(os);
                db.SaveChanges();
            }
        }
Esempio n. 3
0
        public OSModel PutOS(OSModel osm)
        {
            osm.Desc = Utils.CleanString(osm.Desc);
            osm.Version = Utils.CleanString(osm.Version);

            // ReleaseDate can NOT be after ExpirationDate
            if (osm.ExpirationDate.HasValue == true && osm.ReleaseDate.CompareTo(osm.ExpirationDate.Value) > 0)
            {
                Utils.Log(new Logger("SiteData_OSs", "PutOS", "Release date can not be after expiration date.", 56, LogType.ERROR));
                throw new Exception("Release date can not be after expiration date.");
            }

            OS tmpOS = null;
            OSModel retModel = new OSModel();

            using (CanIUpdateEFDB db = new CanIUpdateEFDB())
            {
                tmpOS = db.OSs.Where(o => o.OSId == osm.OSId).FirstOrDefault<OS>();
                if (tmpOS == null)
                {
                    // INSERT (no expiration date on new OS)
                    tmpOS = new OS();
                    tmpOS.Desc			= retModel.Desc			= osm.Desc;
                    tmpOS.ReleaseDate	= retModel.ReleaseDate	= osm.ReleaseDate;
                    tmpOS.Version		= retModel.Version		= osm.Version;
                    db.OSs.Add(tmpOS);
                }
                else
                {
                    // UPDATE
                    tmpOS.Desc			= retModel.Desc			= osm.Desc;
                    tmpOS.ReleaseDate	= retModel.ReleaseDate	= osm.ReleaseDate;
                    tmpOS.Version		= retModel.Version		= osm.Version;
                    if (osm.ExpirationDate.HasValue == true)
                        tmpOS.ExpirationDate = retModel.ExpirationDate = osm.ExpirationDate.Value;
                }
                db.SaveChanges();

                // Add mising field(s) data to model
                retModel.OSId = tmpOS.OSId;
            }

            return retModel;
        }
Esempio n. 4
0
        public List<AppModel> GetAllAppsForOS(int osID)
        {
            OS os = null;
            List<AppModel> appmodels = null;
            using (CanIUpdateEFDB db = new CanIUpdateEFDB())
            {
                os = db.OSs.Where(o => o.OSId == osID).FirstOrDefault<OS>();
                if (os == null)
                    throw new Exception("Missing or invalid OS id.");

                DateTime osReleaseDate = os.ReleaseDate;
                DateTime osExpirationDate = (os.ExpirationDate.HasValue == true) ? os.ExpirationDate.Value : DateTime.Now;

                appmodels = (from a in db.Apps
                             join o in db.OSs on a.MinOSVersionID equals o.OSId
                             select new AppModel()
                             {
                                 AppId = a.AppId,
                                 Desc = a.Desc,
                                 LatestVersion = a.LatestVersion,
                                 MinOSVersion = o.Version,
                                 MinOSVersionID = a.MinOSVersionID,
                                 Name = a.Name,
                                 ReleaseDate = a.ReleaseDate,
                                 AppStatus = AppStatus.NA
                             }).ToList<AppModel>();

                foreach (AppModel appm in appmodels)
                {
                    List<Bug> bugs = db.Bugs.Where(b => b.AppId == appm.AppId).ToList<Bug>();
                    appm.AppStatus = GetAppStatus(bugs, osReleaseDate, osExpirationDate);
                }
            }

            return appmodels;
        }
Esempio n. 5
0
        public AppModel PutApp(AppModel appm)
        {
            // Validation
            int tryInt = -1;
            if (int.TryParse(appm.AppId.ToString(), out tryInt) == false)
                throw new Exception("Missing or invalid App ID.");

            appm.LatestVersion = Utils.CleanString(appm.LatestVersion);
            if (string.IsNullOrEmpty(appm.LatestVersion) == true)
                throw new Exception("Missing or invalid Latest Version.");

            appm.Name = Utils.CleanString(appm.Name);
            if (string.IsNullOrEmpty(appm.Name) == true)
                throw new Exception("Missing or invalid app Name.");

            DateTime tryDate = DateTime.MinValue;
            if (appm.ReleaseDate == null || DateTime.TryParse(appm.ReleaseDate.ToShortDateString(), out tryDate) == false)
                throw new Exception("Missing or invalid Release Date.");

            if (int.TryParse(appm.MinOSVersionID.ToString(), out tryInt) == false)
                throw new Exception("Missing or invalid MinOSVersionID");

            appm.MinOSVersion = Utils.CleanString(appm.MinOSVersion);
            if (string.IsNullOrEmpty(appm.MinOSVersion) == true)
                throw new Exception("Missing or invalid MinOSVersion");

            appm.Desc = Utils.CleanString(appm.Desc);

            // Whew, made it past the validation...
            App tmpApp = null;
            AppModel retModel = new AppModel();

            using (CanIUpdateEFDB db = new CanIUpdateEFDB())
            {
                tmpApp = db.Apps.Where(a => a.AppId == appm.AppId).FirstOrDefault<App>();
                if (tmpApp == null)
                {
                    // INSERT
                    tmpApp = new App();
                    tmpApp.Desc				= retModel.Desc				= appm.Desc;
                    tmpApp.LatestVersion	= retModel.LatestVersion	= appm.LatestVersion;
                    tmpApp.MinOSVersionID	= retModel.MinOSVersionID	= appm.MinOSVersionID;
                    tmpApp.Name				= retModel.Name				= appm.Name;
                    tmpApp.ReleaseDate		= retModel.ReleaseDate		= appm.ReleaseDate;
                    db.Apps.Add(tmpApp);
                }
                else
                {
                    // UPDATE
                    tmpApp.Desc				= retModel.Desc				= appm.Desc;
                    tmpApp.LatestVersion	= retModel.LatestVersion	= appm.LatestVersion;
                    tmpApp.MinOSVersionID	= retModel.MinOSVersionID	= appm.MinOSVersionID;
                    tmpApp.Name				= retModel.Name				= appm.Name;
                    tmpApp.ReleaseDate		= retModel.ReleaseDate		= appm.ReleaseDate;
                }
                db.SaveChanges();

                // Add mising field(s) data to model
                OS os = db.OSs.Where(o => o.OSId == tmpApp.MinOSVersionID).FirstOrDefault<OS>();
                if (os != null)
                    retModel.MinOSVersion = os.Version;

                retModel.AppId = tmpApp.AppId;
            }

            return retModel;
        }
Esempio n. 6
0
        public IEnumerable<AppModel> GetApps(CIURequest req, int osID)
        {
            // CUIRequest Validation
            if (string.IsNullOrEmpty(req.sortFieldName) == false)
            {
                Type t = typeof(AppModel);
                PropertyInfo pi = t.GetProperty(req.sortFieldName);
                if (pi == null)
                {
                    throw new Exception("Invalid Request Property Name.");
                }
            }
            if (string.IsNullOrEmpty(req.sortDirection) == false &&
                (req.sortDirection.ToUpper() != "ASC" && req.sortDirection.ToUpper() != "DESC"))
            {
                throw new Exception("Invalid Sort Direction.");
            }

            // OK, vaidation passed, let's get on with it...
            int totalAppCount = 0;
            OS os = null;
            IEnumerable<AppModel> appmodels = null;
            using (CanIUpdateEFDB db = new CanIUpdateEFDB())
            {
                os = db.OSs.Where(o => o.OSId == osID).FirstOrDefault<OS>();
                if (os == null)
                    throw new Exception("Missing or invalid OS id.");

                DateTime osReleaseDate = os.ReleaseDate;
                DateTime osExpirationDate = (os.ExpirationDate.HasValue == true) ? os.ExpirationDate.Value : DateTime.Now;

                appmodels = (from a in db.Apps
                             join o in db.OSs on a.MinOSVersionID equals o.OSId
                             select new AppModel()
                             {
                                 AppId = a.AppId,
                                 Desc = a.Desc,
                                 LatestVersion = a.LatestVersion,
                                 MinOSVersion = o.Version,
                                 MinOSVersionID = a.MinOSVersionID,
                                 Name = a.Name,
                                 ReleaseDate = a.ReleaseDate
                             }).ToList<AppModel>();

                if (appmodels != null)
                    totalAppCount = appmodels.Count();

                # region Search
                // Limit to App Name Search
                if (string.IsNullOrEmpty(req.searchTerm) == false)
                    appmodels = appmodels.Where(a => a.Name.ToUpper().Contains(req.searchTerm.ToUpper()));
                # endregion

                # region Skip & Take
                if (req.skip == 0 && req.take == 0 || req.skip > 0 && req.take == 0)
                    req.take = totalAppCount;

                appmodels = appmodels.Skip(req.skip).Take(req.take);
                # endregion

                # region Sort
                if (string.IsNullOrEmpty(req.sortFieldName) == true && string.IsNullOrEmpty(req.sortDirection) == true)
                {
                    // Default- no sort parameters provided
                    appmodels = appmodels.OrderBy(a => a.Name);
                }
                if (string.IsNullOrEmpty(req.sortFieldName) == true && string.IsNullOrEmpty(req.sortDirection) == false)
                {
                    if (req.sortDirection.ToUpper() == "ASC")
                    {
                        // Sort By App Name ASC
                        appmodels = appmodels.OrderBy(a => a.Name);
                    }
                    else
                    {
                        // Sort by App Name DESC
                        appmodels = appmodels.OrderByDescending(a => a.Name);
                    }
                }
                if (string.IsNullOrEmpty(req.sortFieldName) == false && string.IsNullOrEmpty(req.sortDirection) == true)
                {
                    // Sort by Field ASC
                    appmodels = appmodels.OrderBy(a => a.GetType().GetProperty(req.sortFieldName).GetValue(a, null));
                    // ThenBy is secondary sort when we can sort by fields other than App Name
                    //.ThenBy(a => a.GetType().GetProperty(a.Name).GetValue(a, null));
                }
                if (string.IsNullOrEmpty(req.sortFieldName) == false && string.IsNullOrEmpty(req.sortDirection) == false)
                {
                    // Sort by Field and Direction
                    if (req.sortDirection.ToUpper() == "ASC")
                    {
                        appmodels = appmodels.OrderBy(a => a.GetType().GetProperty(req.sortFieldName).GetValue(a, null))
                            .ThenBy(a => a.GetType().GetProperty(a.Name).GetValue(a, null));
                    }
                    else
                    {
                        appmodels = appmodels.OrderByDescending(a => a.GetType().GetProperty(req.sortFieldName).GetValue(a, null))
                            .ThenByDescending(a => a.GetType().GetProperty("Name").GetValue(a, null));
                    }
                }
                # endregion

                foreach(AppModel appm in appmodels)
                {
                    List<Bug> bugs = db.Bugs.Where(b => b.AppId == appm.AppId).ToList<Bug>();
                    appm.AppStatus = GetAppStatus(bugs, osReleaseDate, osExpirationDate);
                }
            }

            return appmodels;
        }
Esempio n. 7
0
        public AppModel GetAppModelById(int appid, int osid)
        {
            OS os = null;
            DateTime? osReleaseDate = null;
            DateTime? osExpirationDate = null;
            List<Bug> bugs = null;
            AppModel appm = null;
            using (CanIUpdateEFDB db = new CanIUpdateEFDB())
            {
                os = db.OSs.Where(o => o.OSId == osid).FirstOrDefault<OS>();
                if (os == null)
                    throw new Exception("Missing or invalid OS id.");

                osReleaseDate = os.ReleaseDate;
                osExpirationDate = (os.ExpirationDate.HasValue == true) ? os.ExpirationDate.Value : DateTime.Now;

                bugs = db.Bugs.Where(b => b.AppId == appid).ToList<Bug>();
                appm = (from a in db.Apps
                        join o in db.OSs on a.MinOSVersionID equals o.OSId
                        where a.AppId == appid
                        select new AppModel()
                        {
                            AppId = a.AppId,
                            Desc = a.Desc,
                            LatestVersion = a.LatestVersion,
                            MinOSVersion = o.Version,
                            MinOSVersionID = a.MinOSVersionID,
                            Name = a.Name,
                            ReleaseDate = a.ReleaseDate
                        }).FirstOrDefault<AppModel>();
            }
            if (os != null && appm != null)
                appm.AppStatus = GetAppStatus(bugs, osReleaseDate.Value, osExpirationDate.Value);

            return appm;
        }