Exemplo n.º 1
0
        public void CreateUser(string username, string password)
        {
            if (username == null || password == null)
            {
                throw new ArgumentNullException();
            }
            if (username.Length < DomainConstraints.MinUserName || username.Length > DomainConstraints.MaxUserName || password.Length < DomainConstraints.MinUserPassword)
            {
                throw new ArgumentException();
            }
            if (this.IsUserInSite(username))
            {
                throw new NameAlreadyInUseException(username);
            }

            if (!this.IsSiteExist(this.Name))
            {
                throw new InvalidOperationException();
            }

            User newUser = new User(this, username, password, factoryContext);

            //Attach è necessario perchè quando creo l'utente, il fatto che ci sia la FK al Sito cerca di creare
            //di nuovo il Sito che quindi essendoci già da errore di violazione della PK!!!

            //factoryContext.Configuration.ProxyCreationEnabled = false;

            factoryContext.Users.Add(newUser);
            factoryContext.SaveChanges();

            factoryContext.Database.Connection.Close();
        }
Exemplo n.º 2
0
        public void CreateSiteOnDb(string connectionString, string name, int timezone, int sessionExpirationTimeInSeconds, double minimumBidIncrement)
        {
            if (connectionString == null || name == null)
            {
                throw new ArgumentNullException();
            }
            if (name.Length < DomainConstraints.MinSiteName || name.Length > DomainConstraints.MaxSiteName)
            {
                throw new ArgumentException();
            }
            if (timezone < DomainConstraints.MinTimeZone || timezone > DomainConstraints.MaxTimeZone || sessionExpirationTimeInSeconds < 0 || minimumBidIncrement < 0)
            {
                throw new ArgumentOutOfRangeException();
            }
            if (!isValidConnection(connectionString))
            {
                throw new UnavailableDbException();
            }

            SiteFactoryContext ctx = new SiteFactoryContext(connectionString);

            if (this.isSiteAlreadyInDB(name, ctx))
            {
                throw new NameAlreadyInUseException(name);
            }

            Site newSite = new Site(name, minimumBidIncrement, sessionExpirationTimeInSeconds, timezone, connectionString, ctx, null);

            ctx.Sites.Add(newSite);

            ctx.SaveChanges();

            ctx.Database.Connection.Close();
        }
Exemplo n.º 3
0
        public IAuction CreateAuction(string description, DateTime endsOn, double startingPrice)
        {
            if (!this.IsValid())
            {
                throw new InvalidOperationException();
            }
            if (description == null)
            {
                throw new ArgumentNullException();
            }
            if (description == string.Empty)
            {
                throw new ArgumentException();
            }
            if (startingPrice < 0)
            {
                throw new ArgumentOutOfRangeException();
            }
            if (endsOn < SessionSite.Now)
            {
                throw new UnavailableTimeMachineException();
            }

            int auctionId = factoryContext.Auctions.Count <Auction>();

            Auction newAuction = new Auction(auctionId, User as User, description, endsOn, startingPrice, (User as User).UserSite, factoryContext);

            factoryContext.Auctions.Add(newAuction);

            factoryContext.SaveChanges();

            factoryContext.Database.Connection.Close();

            ValidUntil = ValidUntil.AddSeconds(SessionSite.SessionExpirationInSeconds);

            SaveValidUntil();

            return(newAuction);
        }