コード例 #1
0
        public IActionResult CreateProduct([FromBody] Product newProduct)
        {
            if (newProduct == null)
            {
                return(BadRequest());
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (_productRepository.EntityExists(newProduct.Name))
            {
                return(new JsonResult("productExists"));
            }

            _productRepository.AddEntity(newProduct);
            if (!_productRepository.Save())
            {
                return(StatusCode(500, "A problem happened while handling your request."));
            }

            return(Ok(newProduct));
        }
コード例 #2
0
        public async Task <RegisterUserResult> RegisterUser(RegisterUserDTO register)
        {
            if (IsUserExistsByEmail(register.Email))
            {
                return(RegisterUserResult.EmailExists);
            }

            var user = new User
            {
                Email           = register.Email.SanitizeText(),
                Address         = register.Address.SanitizeText(),
                FirstName       = register.FirstName.SanitizeText(),
                LastName        = register.LastName.SanitizeText(),
                EmailActiveCode = Guid.NewGuid().ToString(),
                Password        = passwordHelper.EncodePasswordMd5(register.Password)
            };

            await userRepository.AddEntity(user);

            await userRepository.SaveChanges();

            //var body = await renderView.RenderToStringAsync("Email/ActivateAccount", user);

            //mailSender.Send("*****@*****.**", "test", body);

            return(RegisterUserResult.Success);
        }
コード例 #3
0
        public IActionResult CreateCustomer([FromBody] Customer newCustomer)
        {
            if (newCustomer == null)
            {
                return(BadRequest());
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (_customerRepository.EntityExists(newCustomer.Name))
            {
                return(new JsonResult("customerExists"));
            }

            _customerRepository.AddEntity(newCustomer);
            if (!_customerRepository.Save())
            {
                return(StatusCode(500, "A problem happened while handling your request."));
            }

            return(Ok(newCustomer));
        }
コード例 #4
0
        public async Task <RegisterUserResult> RegisterUser(RegisterUserDTO register)
        {
            if (IsUserExistByEmail(register.Email))
            {
                return(RegisterUserResult.EmailExist);
            }

            var user = new User
            {
                Email           = register.Email.SanitizeText(),
                Address         = register.Address.SanitizeText(),
                FirstName       = register.FirstName.SanitizeText(),
                LastName        = register.LastName.SanitizeText(),
                EmailActiveCode = Guid.NewGuid().ToString(),
                Password        = _passwordHelper.EncodePasswordMd5(register.Password)
            };

            await _userRepository.AddEntity(user);

            await _userRepository.SaveChanges();


            #region Sending Activated Email
            var body = await _renderView.RenderToStringAsync("Email/_ActivateAccount", user);

            _mailSender.Send("*****@*****.**", "تست فعالسازی", body);
            #endregion

            return(RegisterUserResult.Success);
        }
コード例 #5
0
ファイル: CustomerService.cs プロジェクト: zahid94/MyDeal
        public Customer Registration(Customer Customer)
        {
            try
            {
                if (repository.IsExist(x => x.UserName == Customer.UserName || x.Email == Customer.Email))
                {
                    Customer.Id = -1;
                    return(Customer);
                }
                else
                {
                    repository.AddEntity(Customer);
                    string Email     = Customer.Email;
                    string userName  = Customer.UserName;
                    string subject   = "welcome to mydeal";
                    string emailBody = " thanks you very much . it is your password ";

                    email.Email(Email, userName, subject, emailBody);

                    repository.SaveToDatabase();

                    return(Customer);
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
コード例 #6
0
        public Warehouse AddWarehouse(Warehouse value)
        {
            var newWarehouse = new Warehouse()
            {
                WarehouseName = value.WarehouseName
            };

            _genericRepository.AddEntity(newWarehouse);
            return(newWarehouse);
        }
コード例 #7
0
        public Product AddProduct(Product value)
        {
            var newProduct = new Product()
            {
                DisplayName = value.DisplayName
            };

            _genericRepository.AddEntity(newProduct);
            return(newProduct);
        }
コード例 #8
0
        public Category AddCategory(Category value)
        {
            var newCategory = new Category()
            {
                Name = value.Name
            };

            _genericRepository.AddEntity(newCategory);
            //Trzeba pobrać nowo dodany item do bayz aby zwracalo z ID
            return(newCategory);
        }
コード例 #9
0
        public Person AddPerson(PersonDto value)
        {
            var newPerson = new Person()
            {
                Name = value.Name
            };

            _genericRepository.AddEntity(newPerson);
            //Trzeba pobrać nowo dodany item do bayz aby zwracalo z ID
            return(newPerson);
        }
コード例 #10
0
        public TypeOfCar AddTypeOfCar(TypeOfCarDto value)
        {
            var newTypeOfCar = new TypeOfCar()
            {
                Name = value.Name
            };

            _genericRepository.AddEntity(newTypeOfCar);
            //Trzeba pobrać nowo dodany item do bayz aby zwracalo z ID
            return(newTypeOfCar);
        }
コード例 #11
0
ファイル: BidsService.cs プロジェクト: zahid94/MyDeal
 public Bids AddBids(Bids Bids)
 {
     try
     {
         repository.AddEntity(Bids);
         repository.SaveToDatabase();
         return(Bids);
     }
     catch (Exception)
     {
         throw;
     }
 }
コード例 #12
0
        public async Task <Order> CreateUserOrder(long userId)
        {
            var order = new Order
            {
                UserId = userId
            };

            await _orderRepository.AddEntity(order);

            await _orderRepository.SaveChanges();

            return(order);
        }
コード例 #13
0
        public async Task <bool> AddIpToBlockedIp(string ipAddress)
        {
            if (!string.IsNullOrEmpty(ipAddress) && !string.IsNullOrWhiteSpace(ipAddress))
            {
                var blockIp = new BlockedIp()
                {
                    IpAddress = ipAddress,
                };
                await blockedIpRepository.AddEntity(blockIp);

                await blockedIpRepository.SaveChanges();

                return(true);
            }
            return(false);
        }
コード例 #14
0
        public ResultsWrapperHelper UploadMovie(UploadMovieVM uploadMovieVM)
        {
            var helper = new ResultsWrapperHelper();

            helper.UploadMovieVM = uploadMovieVM;
            var allUsers  = _userRepository.GetAll();
            var allMovies = _movieRepository.GetAll();


            if (string.IsNullOrWhiteSpace(uploadMovieVM.Email))
            {
                helper.Message = "Enter correnct Email";
                return(helper);
            }
            var oldUser = allUsers.FirstOrDefault(u => u.Email.ToLower().Trim() == uploadMovieVM.Email.ToLower().Trim());

            if (oldUser == null)
            {
                helper.Message = "You are Email is not correct";
                return(helper);
            }
            if (oldUser.TypeOfUser != TypeOfUser.AdminUser)
            {
                helper.Message = "You are not Admin";
                return(helper);
            }

            if (string.IsNullOrWhiteSpace(uploadMovieVM.Title))
            {
                helper.Message = "Enter Title";
                return(helper);
            }

            var oldmovie = allMovies.FirstOrDefault(m => m.Title.ToLower().Trim() == uploadMovieVM.Title.ToLower().Trim());

            if (oldmovie != null)
            {
                helper.Message = "The movie is already uploaded... exists";;
                return(helper);
            }

            var newMovie = MapperHelper.MapUploadMovieVmToMovieModel(uploadMovieVM);

            _movieRepository.AddEntity(newMovie);

            return(helper);
        }
コード例 #15
0
ファイル: PageService.cs プロジェクト: zahid94/MyDeal
 public Page AddPage(Page Page)
 {
     try
     {
         if (_repository.IsExist(x => x.Name == Page.Name))
         {
             Page.Id = -1;
             return(Page);
         }
         Page.Name = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(Page.Name.ToLower());
         _repository.AddEntity(Page);
         _repository.SaveToDatabase();
         return(Page);
     }
     catch (Exception)
     {
         throw;
     }
 }
コード例 #16
0
ファイル: UserService.cs プロジェクト: mhrxad/JupiterApi
        public async Task <RegisterUserResult> RegisterUser(RegisterUserDTO register)
        {
            if (IsUserExistsByEmail(register.Email))
            {
                return(RegisterUserResult.EmailExists);
            }

            var user = new User
            {
                Email            = register.Email.SanitizeText(),
                FirstName        = register.FirstName.SanitizeText(),
                LastName         = register.LastName.SanitizeText(),
                Avatar           = register.Avatar,
                DateOfBirth      = DateTime.ParseExact(register.DateOfBirth, "yyyy/MM/dd", CultureInfo.InvariantCulture),
                Gender           = register.Gender,
                MembershipNumber = register.MembershipNumber.SanitizeText(),
                MobileNumber     = register.MobileNumber.SanitizeText(),
                NationalCode     = register.NationalCode.SanitizeText(),
                EmailActiveCode  = Guid.NewGuid().ToString("N").Substring(0, 8),
                Password         = passwordHelper.EncodePasswordMd5(register.Password)
            };

            await userRepository.AddEntity(user);

            await userRepository.SaveChanges();

            var role = new UserRole
            {
                UserId = user.Id,
                RoleId = 3
            };

            await userRoleRepository.AddEntity(role);

            await userRoleRepository.SaveChanges();

            var body = await renderView.RenderToStringAsync("Email/ActivateAccount", user);

            mailSender.Send(user.Email, "فعال سازی حساب کاربری", body);

            return(RegisterUserResult.Success);
        }
コード例 #17
0
 public HomePageSlider AddSlider(HomePageSlider Slider)
 {
     try
     {
         if (repository.IsExist(x => x.Name == Slider.Name || x.ImageName == Slider.ImageName))
         {
             Slider.Id = -1;
             return(Slider);
         }
         else
         {
             repository.AddEntity(Slider);
             repository.SaveToDatabase();
             return(Slider);
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
コード例 #18
0
 public Product AddProduct(Product product)
 {
     try
     {
         if (_repository.IsExist(x => x.Title == product.Title))
         {
             product.Id = -1;
             return(product);
         }
         else
         {
             _repository.AddEntity(product);
             _repository.SaveToDatabase();
             return(product);
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
コード例 #19
0
        public async Task AddProductToOrder(long userId, long productId, int count)
        {
            var user = await _userService.GetUserByUserId(userId);

            var product = await _productService.GetProductForUserOrder(productId);

            if (user != null && product != null)
            {
                var order = await GetUserOpenOrder(userId);

                if (count < 1)
                {
                    count = 1;
                }


                var details = await GetOrderDetails(order.Id);

                var existsDetail = details.SingleOrDefault(s => s.ProductId == productId && !s.IsDelete);

                if (existsDetail != null)
                {
                    existsDetail.Count += count;
                    _orderDetailRepository.UpdateEntity(existsDetail);
                }
                else
                {
                    var detail = new OrderDetail
                    {
                        OrderId   = order.Id,
                        ProductId = productId,
                        Count     = count,
                        Price     = product.Price
                    };
                    await _orderDetailRepository.AddEntity(detail);
                }

                await _orderDetailRepository.SaveChanges();
            }
        }
コード例 #20
0
 public Category AddCategory(Category Category)
 {
     try
     {
         if (_repository.IsExist(x => x.Name == Category.Name))
         {
             Category.Id = -1;
             return(Category);
         }
         else
         {
             Category.Name = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(Category.Name.ToLower());
             _repository.AddEntity(Category);
             _repository.SaveToDatabase();
             return(Category);
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
コード例 #21
0
        public ResultsWrapperHelper MovieById(OrderDetailsVM orderDetails)
        {
            var movie  = _movieRepository.GetById(orderDetails.IdOfMovie);
            var helper = new ResultsWrapperHelper();

            helper.OrderDetailsVM = orderDetails;

            if (movie == null)
            {
                helper.Message = "There is no movie like that, try again";
                return(helper);
            }

            var user = MapperHelper.MapOrderDetailsVmToUserModel(orderDetails);

            if (string.IsNullOrEmpty(user.Email))
            {
                helper.Message = "You must have valid email";
                return(helper);
            }

            if (_userRepository.GetAll()
                .SingleOrDefault(u => u.Email.ToLower().Trim() == user.Email.ToLower().Trim()) == null)
            {
                _userRepository.AddEntity(user);
            }
            var stats = new OrderMovieStatsHistory()
            {
                MovieId = movie.Id,
                UserId  = user.Id
            };

            _orderRepository.AddEntity(stats);

            return(helper);
        }
コード例 #22
0
        public async Task AddProduct(Product product)
        {
            await _productRepository.AddEntity(product);

            await _productRepository.SaveChanges();
        }
コード例 #23
0
        public async Task AddCommentToProduct(ProductComment comment)
        {
            await _productCommentRepository.AddEntity(comment);

            await _productCommentRepository.SaveChanges();
        }
コード例 #24
0
        public async Task AddMessage(Message message)
        {
            await messageRepository.AddEntity(message);

            await messageRepository.SaveChanges();
        }
コード例 #25
0
        public async Task AddUserToStatistic(string ip)
        {
            var httpContext = _httpContextAccessor.HttpContext;
            var blockedIP   = await blockedIpRepository.GetQuery().AsQueryable()
                              .Where(p => !p.IsDelete).ToListAsync();

            if (!blockedIP.Any(ip => ip.IpAddress.Equals(GetIPAddress())))
            {
                var statistic = new Statistics();
                statistic.IpAddress  = GetIPAddress();
                statistic.UserOs     = GetUserOS(httpContext.Request.Headers["User-Agent"].ToString());
                statistic.PageViewed = httpContext.Request.Path;
                statistic.Referer    = httpContext.Request.Headers["Referer"].ToString() ?? "Direct";
                statistic.UserAgent  = httpContext.Request.Headers["User-Agent"].ToString();
                statistic.DateStamp  = DateTime.Now;

                await statisticsRepository.AddEntity(statistic);

                await statisticsRepository.SaveChanges();

                #region get location
                var jsonDeserialize = await GetLocation();

                var countries = await countryRepository.GetQuery().AsQueryable()
                                .AnyAsync(c => c.CountryCode.Equals(jsonDeserialize.CountryCode));

                if (countries)
                {
                    //then Update the ViewCount
                    Country currentCountry = countryRepository.GetQuery()
                                             .First(cc => cc.CountryCode.Equals(jsonDeserialize.CountryCode));
                    currentCountry.ViewCount++;
                    await countryRepository.SaveChanges();
                }
                else
                {
                    //then add this Country To Database
                    var newCountry = new Country()
                    {
                        CountryCode = jsonDeserialize.CountryCode,
                        CountryName = jsonDeserialize.CountryName,
                        Latitude    = jsonDeserialize.Latitude,
                        Longitude   = jsonDeserialize.Longitude,
                        City        = jsonDeserialize.City,
                        RegionName  = jsonDeserialize.RegionName,
                        RegionCode  = jsonDeserialize.RegionCode,
                        ViewCount   = 1
                    };
                    await countryRepository.AddEntity(newCountry);

                    await countryRepository.SaveChanges();
                }
                #endregion

                #region Get Country Visitors
                // Get Country Visitors
                //my ipStack Website Details = access_key = 74c3142e849d032aa8238f174421a424
                //https://ipstack.com/quickstart get access_key

                //XmlDocument xdoc = new XmlDocument();
                //xdoc.LoadXml("https://api.ipstack.com/" + GetIPAddress() + "?access_key=74c3142e849d032aa8238f174421a424");
                //var country = xdoc.Descendants("Response").Select(c => new
                //{
                //    IpAddress = c.Element("IP")?.Value,
                //    CountryCode = c.Element("CountryCode")?.Value,
                //    CountryName = c.Element("CountryName")?.Value,
                //    RegionCode = c.Element("RegionCode")?.Value,
                //    RegionName = c.Element("RegionName")?.Value,
                //    City = c.Element("City")?.Value,
                //    ZipCode = c.Element("ZipCode")?.Value,
                //    TimeZone = c.Element("TimeZone")?.Value,
                //    Latitude = c.Element("Latitude")?.Value,
                //    Longitude = c.Element("Longitude")?.Value,
                //    MetroCode = c.Element("MetroCode")?.Value,
                //});

                //var countryData = country.FirstChild();

                ////Check If The Country Is already in database or not
                //var countries = countryRepository
                //    .GetQuery().Any(c => c.CountryCode.Equals(countryData.CountryCode));

                //if (countries)
                //{
                //    //then Update the ViewCount
                //    Country currentCountry = countryRepository.GetQuery()
                //        .First(cc => cc.CountryCode.Equals(countryData.CountryCode));
                //    currentCountry.ViewCount++;
                //    await countryRepository.SaveChanges();
                //}
                //else
                //{
                //    //then add this Country To Database
                //    var newCountry = new Country()
                //    {
                //        CountryCode = countryData.CountryCode,
                //        CountryName = countryData.CountryName,
                //        Latitude = countryData.Latitude,
                //        Longitude = countryData.Longitude,
                //        ViewCount = 1
                //    };
                //    await countryRepository.AddEntity(newCountry);
                //    await countryRepository.SaveChanges();
                //}
                #endregion
            }
        }
コード例 #26
0
        public async Task AddSlider(Slider slider)
        {
            await _sliderRepository.AddEntity(slider);

            await _sliderRepository.SaveChanges();
        }
コード例 #27
0
 public Task <T> AddEntity(T entity)
 {
     return(Repository.AddEntity(entity));
 }
コード例 #28
0
ファイル: CommentService.cs プロジェクト: zahid94/MyDeal
 public Comment Add(Comment comment)
 {
     repository.AddEntity(comment);
     repository.SaveToDatabase();
     return(comment);
 }