Пример #1
0
        public string NewRegistration(string organization)
        {
            Log.Information("VersionRepo:NewRegistration:Beginning");
            Log.Information("1. Check if the organization already exists");
            if (_context.Version.Any(e => e.Organization == organization))
            {
                Log.Error($"{organization} already exists in the database.");
                return("Sorry, This Organizaition already exits");
            }

            Log.Information("2. Create a new guid");
            var guid = Guid.NewGuid();

            Log.Information("3. Save to the db.Table");
            MyVersion registration = new MyVersion();

            registration.Key          = guid.ToString();
            registration.Organization = organization;
            _context.Add(registration);
            _context.SaveChanges();

            Log.Information("4. Return the guid");
            Log.Information("VersionRepo:NewRegistration:Completed");
            return(guid.ToString());
        }
Пример #2
0
        public string NewProduct(int versionId, string name)
        {
            var version = _context.Version.Where(e => e.Id == versionId).FirstOrDefault();

            if (ProductExist(version.Id, name))
            {
                return("Sorry, this product already exists");
            }
            Product product = new Product();

            product.Version  = version;
            product.Name     = name;
            product.Major    = 0;
            product.Minor    = 0;
            product.Patch    = 0;
            product.Revision = 0;
            product.Master   = "0.0.0.0";
            _context.Product.Add(product);
            _context.SaveChanges();

            return(product.Master);
        }
Пример #3
0
        public void Save(VersionModel version)
        {
            try
            {
                using (var ctx = new VersionContext())
                {
                    var query = ctx.VersionModels.SqlQuery(@"
                            SELECT * 
                            FROM dbo.VersionModels 
                            WHERE ComputerGroup=@ComputerGroup
                            AND ComputerName=@ComputerName
                            AND ApplicationName=@ApplicationName",
                                                           new SqlParameter("@ComputerGroup", version.ComputerGroup),
                                                           new SqlParameter("@ComputerName", version.ComputerName),
                                                           new SqlParameter("@ApplicationName", version.ApplicationName));

                    var model = query.FirstAsync().Result;
                    if (model != null)
                    {
                        model.ApplicationVersion = version.ApplicationVersion;
                        model.LastCheckTimestamp = DateTime.Now;
                    }
                    else
                    {
                        version.LastCheckTimestamp = DateTime.Now;
                        ctx.VersionModels.Add(version);
                    }

                    ctx.SaveChanges();
                }
            }
            catch (Exception e)
            {
                InternalServerError(e);
            }
        }
 public void TearDown()
 {
     clearVersions();
     clearProducts();
     _database.SaveChanges();
 }