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)); }
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); }
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)); }
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); }
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; } }
public Warehouse AddWarehouse(Warehouse value) { var newWarehouse = new Warehouse() { WarehouseName = value.WarehouseName }; _genericRepository.AddEntity(newWarehouse); return(newWarehouse); }
public Product AddProduct(Product value) { var newProduct = new Product() { DisplayName = value.DisplayName }; _genericRepository.AddEntity(newProduct); return(newProduct); }
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); }
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); }
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); }
public Bids AddBids(Bids Bids) { try { repository.AddEntity(Bids); repository.SaveToDatabase(); return(Bids); } catch (Exception) { throw; } }
public async Task <Order> CreateUserOrder(long userId) { var order = new Order { UserId = userId }; await _orderRepository.AddEntity(order); await _orderRepository.SaveChanges(); return(order); }
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); }
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); }
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; } }
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); }
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; } }
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; } }
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(); } }
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; } }
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); }
public async Task AddProduct(Product product) { await _productRepository.AddEntity(product); await _productRepository.SaveChanges(); }
public async Task AddCommentToProduct(ProductComment comment) { await _productCommentRepository.AddEntity(comment); await _productCommentRepository.SaveChanges(); }
public async Task AddMessage(Message message) { await messageRepository.AddEntity(message); await messageRepository.SaveChanges(); }
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 } }
public async Task AddSlider(Slider slider) { await _sliderRepository.AddEntity(slider); await _sliderRepository.SaveChanges(); }
public Task <T> AddEntity(T entity) { return(Repository.AddEntity(entity)); }
public Comment Add(Comment comment) { repository.AddEntity(comment); repository.SaveToDatabase(); return(comment); }