コード例 #1
0
        public void AddCategoriesForSportCenter(IEnumerable <string> categoriesNames, string sportCenterName)
        {
            var sportCenter = sportCentesDb.All().FirstOrDefault(x => x.Name == sportCenterName);

            foreach (var name in categoriesNames)
            {
                var currentCategory = this.sportCategoriesDb.All().FirstOrDefault(x => x.Name == name);

                if (currentCategory != null)
                {
                    currentCategory.SportCenters.Add(sportCenter);
                }
                else
                {
                    if (string.IsNullOrWhiteSpace(name))
                    {
                        continue;
                    }
                    sportCategoriesDb.Add(new SportCategory()
                    {
                        Name = name.Trim(), SportCenters = new List <SportCenter>()
                        {
                            sportCenter
                        }
                    });
                }
            }
            sportCategoriesDb.SaveChanges();
        }
コード例 #2
0
        public void AddDefaultPages(List <Page> pageList)
        {
            foreach (var page in pageList)
            {
                pages.Add(page);
            }

            pages.SaveChanges();
        }
コード例 #3
0
        public async Task <bool> CreateDocument(string name, IFormFile file)
        {
            int result = -1;

            using (var memoryStream = new MemoryStream())
            {
                file.CopyTo(memoryStream);

                // Upload the file if less than 8 MB
                if (memoryStream.Length <= 8388608)
                {
                    var fileforDb = new Document()
                    {
                        Name      = name,
                        Bytes     = memoryStream.ToArray(),
                        Size      = memoryStream.Length,
                        CreatedOn = DateTime.Now,
                    };

                    repository.Add(fileforDb);

                    result = await repository.SaveChangesAsync();
                }

                return(result > 0 ? true : false);
            }
        }
コード例 #4
0
        public async Task <string> CreateAsync(Video video)
        {
            videoRepository.Add(video);
            await videoRepository.SaveChangesAsync();

            return(video.Id);
        }
コード例 #5
0
 public void Create(string city, string neighbour)
 {
     addressesDb.Add(new Address()
     {
         City = city, Neighborhood = neighbour
     });
     addressesDb.SaveChanges();
 }
コード例 #6
0
        public void AddPicture(string name, string fileName)
        {
            Picture pic = new Picture
            {
                Name       = name,
                UrlToImage = Path.Combine("Images", fileName)
            };

            pictures.Add(pic);
            pictures.SaveChanges();
        }
コード例 #7
0
        public void AddNewVideo(string name, string videoUrl)
        {
            Video vid = new Video
            {
                Name     = name,
                VideoUrl = videoUrl
            };

            videos.Add(vid);
            videos.SaveChanges();
        }
コード例 #8
0
        public async Task <Comment> AddAsync(Comment comment)
        {
            repository.Add(comment);
            await repository.SaveChangesAsync();

            var commentFromDb = await repository
                                .All()
                                .Include(c => c.Author)
                                .SingleOrDefaultAsync(c => c.Id == comment.Id);

            return(commentFromDb);
        }
コード例 #9
0
        public void AddPost(string title, string content, string id)
        {
            Post post = new Post
            {
                Title    = title,
                Content  = content,
                AuthorId = id
            };

            posts.Add(post);

            posts.SaveChanges();
        }
コード例 #10
0
        public async Task <GameScore> Create(string userId, string userEmail, int highScore)
        {
            var newGameScore = new GameScore()
            {
                UserId    = userId,
                UserEmail = userEmail,
                HighScore = highScore
            };

            _gameScoreRepository.Add(newGameScore);
            await _gameScoreRepository.SaveChangesAsync();

            return(newGameScore);
        }
コード例 #11
0
        public async Task <CatalogItem> CreateNew(string name, decimal price, string color)
        {
            var catalogItem = new CatalogItem()
            {
                Name  = name,
                Price = price,
                Color = color,
            };

            _catalogItemsRepository.Add(catalogItem);

            await _catalogItemsRepository.SaveChangesAsync();

            return(catalogItem);
        }
コード例 #12
0
        public Log AddNewLog(string category, string content)
        {
            Log log = new Log
            {
                CreatedOn = DateTime.Now,
                Category  = category,
                Content   = content
            };

            logs.Add(log);

            logs.SaveChanges();

            return(log);
        }
コード例 #13
0
        public void SendMessage(string recieverId, string senderId, string content)
        {
            var reciever = usersDb.All().FirstOrDefault(x => x.Id == recieverId);
            var author   = usersDb.All().FirstOrDefault(x => x.Id == senderId);

            if (author != null && reciever != null)
            {
                var message = new Message()
                {
                    Reciever = reciever, Author = author, Content = content
                };
                messagesDb.Add(message);
                messagesDb.SaveChanges();
            }
            else
            {
                throw new ArgumentNullException("Invalid user ids");
            }
        }
コード例 #14
0
        public ActionResult Ask(AskInputModel input)
        {
            if (ModelState.IsValid)
            {
                var userId = User.Identity.GetUserId();

                var post = new Post
                {
                    Title    = input.Title,
                    Content  = sanitizer.Sanitize(input.Content),
                    AuthorId = userId
                               //TODO: Tags
                };

                posts.Add(post);
                posts.SaveChanges();
                return(RedirectToAction("Display", new { id = post.Id, url = "new" }));
            }
            return(View(input));
        }
コード例 #15
0
 public async Task AddAsync(Rate rate)
 {
     repository.Add(rate);
     await repository.SaveChangesAsync();
 }
コード例 #16
0
        public async Task SyncOrders(SyncOrdersViewModel model)
        {
            var orderTickets = model.Orders.Select(x => x.OrderTicket);
            var orderSource  = model.Orders.Select(x => x.Source);

            var orders = await _repo
                         .All()
                         .Where(x => orderTickets.Contains(x.OrderTicket) && orderSource.Contains(x.Source))
                         .ToListAsync();

            foreach (var reqeustOrder in model.Orders)
            {
                var currOrder = orders.FirstOrDefault(x => x.OrderTicket == reqeustOrder.OrderTicket);

                if (currOrder != null)
                {
                    currOrder.OrderTicket = reqeustOrder.OrderTicket;
                    //currOrder.Status = reqeustOrder.Status;
                    currOrder.OrderSymbol     = reqeustOrder.OrderSymbol;
                    currOrder.OrderOpenPrice  = reqeustOrder.OrderOpenPrice;
                    currOrder.OrderTakeProfit = reqeustOrder.OrderTakeProfit;
                    currOrder.OrderStopLoss   = reqeustOrder.OrderStopLoss;
                    currOrder.OrderOpenTime   = reqeustOrder.OrderOpenTime;
                    currOrder.OrderCloseTime  = reqeustOrder.OrderCloseTime;
                    currOrder.OrderExpiration = reqeustOrder.OrderExpiration;
                    currOrder.OrderProfit     = reqeustOrder.OrderProfit;
                    currOrder.OrderLots       = reqeustOrder.OrderLots;
                    currOrder.OrderType       = reqeustOrder.OrderType;
                    currOrder.OrderCommission = reqeustOrder.OrderCommission;
                    currOrder.OrderSwap       = reqeustOrder.OrderSwap;
                    currOrder.Source          = reqeustOrder.Source;
                }
                else
                {
                    var newOrder = new TradingOrder()
                    {
                        OrderTicket     = reqeustOrder.OrderTicket,
                        Status          = "active",//reqeustOrder.Status,
                        OrderSymbol     = reqeustOrder.OrderSymbol,
                        OrderOpenPrice  = reqeustOrder.OrderOpenPrice,
                        OrderTakeProfit = reqeustOrder.OrderTakeProfit,
                        OrderStopLoss   = reqeustOrder.OrderStopLoss,
                        OrderOpenTime   = reqeustOrder.OrderOpenTime,
                        OrderCloseTime  = reqeustOrder.OrderCloseTime,
                        OrderExpiration = reqeustOrder.OrderExpiration,
                        OrderProfit     = reqeustOrder.OrderProfit,
                        OrderLots       = reqeustOrder.OrderLots,
                        OrderType       = reqeustOrder.OrderType,
                        OrderCommission = reqeustOrder.OrderCommission,
                        OrderSwap       = reqeustOrder.OrderSwap,
                        Source          = reqeustOrder.Source,
                    };

                    _repo.Add(newOrder);
                }
            }

            // update missing as deleted
            var missingOrders = await _repo
                                .All()
                                .Where(x => orderSource.Contains(x.Source) && !orderTickets.Contains(x.OrderTicket) && x.Status == "active")
                                .ToListAsync();

            missingOrders.ForEach(x => x.Status = "closed");

            await _repo.SaveChangesAsync();
        }