Пример #1
0
        /// <summary>
        /// Deletes the URL
        /// </summary>
        public override void Delete()
        {
            if (Nintex.TestContext.IsTesting == true)
            {
                this.Id = 0;
                return;
            }

            //For now we are having copy of same URL for all needy Clients. Later this can be optimized
            var dbURL = new DataLayer.URL {
                Id = this.Id
            };

            DataLayer.NintexUrlDbEntities db = new NintexUrlDbEntities();
            db.URLs.Attach(dbURL);
            db.URLs.Remove(dbURL);
            try
            {
                db.SaveChanges();
            }
            catch
            {
                throw;
            }
        }
Пример #2
0
        public override void Add()
        {
            if (Nintex.TestContext.IsTesting == true)
            {
                this.Id = 1;
                GenerateShortURL(this, new BusinessLayer.URLShortener.Base64Shortener());
                return;
            }

            //CF-1 Insert in repository
            //CF-2 Generate the shorturl from generated Id
            //CF-3 update the URL in repository with generated shortUrl

            //CF-1
            //preparing the DataLayer URL
            DataLayer.URL dbURL = new DataLayer.URL();
            dbURL.LongURL  = this.LongURL;
            dbURL.ShortURL = this.ShortURL;
            dbURL.Clients  = new List <DataLayer.Client>();
            //For now we are having copy of same URL for all needy Clients. Later this can be optimized
            foreach (Client client in Clients)
            {
                dbURL.Clients.Add(new DataLayer.Client {
                    Id = client.Id
                });
            }

            DataLayer.NintexUrlDbEntities db = new NintexUrlDbEntities();
            db.URLs.Attach(dbURL);
            db.URLs.Add(dbURL);
            try
            {
                //saving the URL in repository to get its Id
                db.SaveChanges();

                Id = dbURL.Id;

                //CF-2
                //generating the short URL using the strategy pattern
                GenerateShortURL(this, new BusinessLayer.URLShortener.Base64Shortener());

                dbURL.ShortURL = this.ShortURL;

                //CF-3
                //updating the repository with generated short URL
                db.SaveChanges();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }