Ejemplo n.º 1
0
 public HomeController(ModelContext context, IHostingEnvironment hostingEnvironment)
 {
     _context            = context;
     homeService         = new HomeService(_context);
     buyerService        = new BuyerService(_context);
     _hostingEnvironment = hostingEnvironment;
 }
Ejemplo n.º 2
0
        protected void btn_Click(object sender, EventArgs e)
        {
            string name = txt.Text.Trim();
            string paw  = pwd.Text.Trim();

            try
            {
                SqlDataReader dr = BuyerService.Login(name, paw);
                if (dr.Read())
                {
                    Session["Buyers_name"] = txt.Text;
                    Session["Buyers_id"]   = dr["Buyers_id"].ToString();
                    Response.Redirect("index.aspx");
                }
                else
                {
                    //MessageBox.Show("用户名或者密码错误 ");
                    pwd.Text = "";
                    pwd.Focus();
                }
            }

            catch (Exception ex)
            {
                Response.Write("错误原因:" + ex);
            }
        }
 public EntryController(ModelContext context)
 {
     _context      = context;
     service       = new BuyerService(_context);
     sellerService = new SellerService(_context);
     adminService  = new AdministratorService(_context);
 }
Ejemplo n.º 4
0
        public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            List <ValidationResult> validationResult = new List <ValidationResult>();

            if (string.IsNullOrWhiteSpace(this.Code))
            {
                validationResult.Add(new ValidationResult("Code is required", new List <string> {
                    "code"
                }));
            }

            if (string.IsNullOrWhiteSpace(this.Name))
            {
                validationResult.Add(new ValidationResult("Name is required", new List <string> {
                    "name"
                }));
            }

            if (this.Tempo.Equals(null))
            {
                this.Tempo = 0;
            }
            else if (this.Tempo < 0)
            {
                validationResult.Add(new ValidationResult("Tempo must be 0 or more", new List <string> {
                    "tempo"
                }));
            }

            if (string.IsNullOrWhiteSpace(this.Country))
            {
                validationResult.Add(new ValidationResult("Country is required", new List <string> {
                    "country"
                }));
            }

            if (string.IsNullOrWhiteSpace(this.Type))
            {
                validationResult.Add(new ValidationResult("Type is required", new List <string> {
                    "type"
                }));
            }

            if (validationResult.Count.Equals(0))
            {
                /* Service Validation */
                BuyerService service = (BuyerService)validationContext.GetService(typeof(BuyerService));

                if (service.DbContext.Set <Buyer>().Count(r => r._IsDeleted.Equals(false) && r.Id != this.Id && r.Code.Equals(this.Code)) > 0) /* Code Unique */
                {
                    validationResult.Add(new ValidationResult("Code already exists", new List <string> {
                        "code"
                    }));
                }
            }

            return(validationResult);
        }
Ejemplo n.º 5
0
        private void BindProduct1()
        {
            DataTable dt = BuyerService.SelectAll();

            if (dt != null && dt.Rows.Count != 0)
            {
                ListView1.DataSource = dt;
                ListView1.DataBind();
            }
        }
Ejemplo n.º 6
0
 public BaseController()
 {
     _advertisementService = new AdvertisementService();
     _sellerService        = new SellerService();
     _buyerService         = new BuyerService();
     _locationService      = new LocationService();
     _userService          = new UserService();
     UserId              = GetSession <UserSessionInfo>(USER_SESSION)?.Id ?? 0;
     _categoryService    = new CategoryService();
     _subCategoryService = new SubCategoryService();
 }
        public AccountController(ModelContext context, IHostingEnvironment hostingEnvironment)
        {
            _context = context;
            service1 = new SecurityService(_context);
            service2 = new BuyerService(_context);
            favoriteProductService    = new FavoriteProductService(_context);
            followShopService         = new FollowShopService(_context);
            receiveInformationService = new ReceiveInformationService(_context);
            buyerCouponService        = new BuyerCouponService(_context);
            orderService = new OrderService(_context);

            _hostingEnvironment = hostingEnvironment;
        }
Ejemplo n.º 8
0
        public async Task ValidateAsync_PatientExists_DoesNothing()
        {
            // Arrange
            var patientContainer = new Mock <IBuyerContainer>();

            var patient         = new Buyer();
            var streetService   = new Mock <ICityService>();
            var patientDAL      = new Mock <IBuyerDAL>();
            var patientIdentity = new Mock <IBuyerIdentity>();

            patientDAL.Setup(x => x.GetAsync(patientIdentity.Object)).ReturnsAsync(patient);

            var patientGetService = new BuyerService(patientDAL.Object, streetService.Object);

            // Act
            var action = new Func <Task>(() => patientGetService.ValidateAsync(patientContainer.Object));

            // Assert
            await action.Should().NotThrowAsync <Exception>();
        }
Ejemplo n.º 9
0
        public async Task TestCreateModel_InvalidEmail()
        {
            BuyerService service = this.Service;

            Models.Buyer testData = new Models.Buyer()
            {
                Name  = "Test Email",
                Email = "InvalidEmail"
            };

            try
            {
                await service.CreateModel(testData);
            }
            catch (ServiceValidationExeption ex)
            {
                ValidationResult numericNameException = ex.ValidationResults.FirstOrDefault(r => r.MemberNames.Contains("Email"));
                Assert.NotNull(numericNameException);
            }
        }
Ejemplo n.º 10
0
        public async Task CreateAsync_PatientValidationSucceed_CreatesPatient()
        {
            // Arrange
            var patient  = new BuyerUpdateModel();
            var expected = new Buyer();

            var streetService = new Mock <ICityService>();

            streetService.Setup(x => x.ValidateAsync(patient));

            var patientDAL = new Mock <IBuyerDAL>();

            patientDAL.Setup(x => x.InsertAsync(patient)).ReturnsAsync(expected);

            var patientService = new BuyerService(patientDAL.Object, streetService.Object);

            // Act
            var result = await patientService.CreateAsync(patient);

            // Assert
            result.Should().Be(expected);
        }
Ejemplo n.º 11
0
        public async Task ValidateAsync_PatientNotExists_ThrowsError()
        {
            // Arrange
            var fixture = new Fixture();
            var id      = fixture.Create <int>();

            var patientContainer = new Mock <IBuyerContainer>();

            patientContainer.Setup(x => x.BuyerId).Returns(id);
            var patientIdentity = new Mock <IBuyerIdentity>();
            var streetService   = new Mock <ICityService>();
            var patient         = new Buyer();
            var patientDAL      = new Mock <IBuyerDAL>();

            patientDAL.Setup(x => x.GetAsync(patientIdentity.Object)).ReturnsAsync((Buyer)null);

            var patientGetService = new BuyerService(patientDAL.Object, streetService.Object);

            // Act
            var action = new Func <Task>(() => patientGetService.ValidateAsync(patientContainer.Object));
            // Assert
            await action.Should().ThrowAsync <InvalidOperationException>($"Buyer not found by id {id}");
        }
Ejemplo n.º 12
0
        public async Task CreateAsync_PatientValidationFailed_ThrowsError()
        {
            // Arrange
            var fixture  = new Fixture();
            var patient  = new BuyerUpdateModel();
            var expected = fixture.Create <string>();

            var streetService = new Mock <ICityService>();

            streetService
            .Setup(x => x.ValidateAsync(patient))
            .Throws(new InvalidOperationException(expected));

            var patientDAL = new Mock <IBuyerDAL>();

            var patientService = new BuyerService(patientDAL.Object, streetService.Object);

            var action = new Func <Task>(() => patientService.CreateAsync(patient));

            // Assert
            await action.Should().ThrowAsync <InvalidOperationException>().WithMessage(expected);

            patientDAL.Verify(x => x.InsertAsync(patient), Times.Never);
        }
Ejemplo n.º 13
0
        public BuyerDomainServiceTest()
        {
            buyerRepositoryMock = NSubstitute.Substitute.For <IBuyerRepository>();

            buyerService = new BuyerService(buyerRepositoryMock, new Logger());
        }
Ejemplo n.º 14
0
 public BuyerController()
 {
     buyerService = new BuyerService();
 }
Ejemplo n.º 15
0
 public BuyerController(BuyerService buyerService)
 {
     this.buyerService = buyerService;
 }
Ejemplo n.º 16
0
        public IHttpActionResult Test()
        {
            try
            {
                Buyer buyer1 = new Buyer();
                buyer1.Email = "*****@*****.**";
                buyer1.Name  = "Pablo";
                buyer1.Phone = "123456789";
                Buyer buyer2 = new Buyer();
                buyer2.Email = "*****@*****.**";
                buyer2.Name  = "Pablo U.";
                buyer2.Phone = "897654123";
                Buyer buyer3 = new Buyer();
                buyer3.Email = "*****@*****.**";
                buyer3.Name  = "Luis";
                buyer3.Phone = "22233666";
                BuyerService buyerService = new BuyerService();
                buyerService.Add(buyer1);
                buyerService.Add(buyer2);
                buyerService.Add(buyer3);

                Seller seller1 = new Seller();
                seller1.Email = "*****@*****.**";
                seller1.Name  = "Diego";
                seller1.Phone = "456666";
                Seller seller2 = new Seller();
                seller2.Email = "*****@*****.**";
                seller2.Name  = "Godin";
                seller2.Phone = "357159";
                Seller seller3 = new Seller();
                seller3.Email = "*****@*****.**";
                seller3.Name  = "Carlitos";
                seller3.Phone = "5254";
                SellerService sellerService = new SellerService();
                sellerService.Add(seller1);
                sellerService.Add(seller2);
                sellerService.Add(seller3);


                Publication publication = new Publication();
                publication.IdBuyer         = 1;
                publication.Buyer           = buyer1;
                publication.Description     = "Computador I7";
                publication.DescriptionItem = "Compu I7";
                publication.Price           = 1200;
                publication.PriceMinItem    = 800;
                publication.PriceMaxItem    = 1200;

                publicationService.Add(publication);

                Publication publication2 = new Publication();
                publication2.IdBuyer         = 1;
                publication2.Buyer           = buyer1;
                publication2.Description     = "Computador I5";
                publication2.DescriptionItem = "Compu I5";
                publication2.Price           = 1000;
                publication2.PriceMinItem    = 500;
                publication2.PriceMaxItem    = 1000;

                publicationService.Add(publication2);


                Publication publication3 = new Publication();
                publication3.IdBuyer         = 1;
                publication3.Buyer           = buyer1;
                publication3.Description     = "Computador I3";
                publication3.DescriptionItem = "Compu I3";
                publication3.Price           = 800;
                publication3.PriceMinItem    = 500;
                publication3.PriceMaxItem    = 800;

                publicationService.Add(publication3);

                Offer offer1 = new Offer();
                offer1.IdPublication   = 1;
                offer1.IdSeller        = 1;
                offer1.DescriptionItem = "Una compu I7";
                offer1.PriceItem       = 1100;


                Offer offer2 = new Offer();
                offer2.IdPublication   = 1;
                offer2.IdSeller        = 2;
                offer2.DescriptionItem = "Una compu I7";
                offer2.PriceItem       = 1150;

                Offer offer3 = new Offer();
                offer3.IdPublication   = 2;
                offer3.IdSeller        = 3;
                offer3.DescriptionItem = "Una compu I5";
                offer3.PriceItem       = 900;


                OfferService offerService = new OfferService();
                offerService.Add(offer1);
                offerService.Add(offer2);
                offerService.Add(offer3);


                return(Ok());
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }