예제 #1
0
 public ActionResult AddAccount(NewAssetModel model)
 {
     var user = _userRepository.GetByUsername(User.Identity.Name);
     var category = _categoryRepository.GetById(model.Category);
     if(category== null)
         throw new Exception("Category is null");
     var parser = SocialParserFactory.Create(category.Name);
     var jsonData = parser.Parse(Request.Form);
     if(string.IsNullOrEmpty(jsonData.Data))
         throw new Exception("Empty data");
     //var isDuplicateAsset = _assetRepository.GetByUserId(user.Id).Any(x => x.Url == jsonData.Url);
     //if(isDuplicateAsset)
     //return RedirectToAction("Message", "Error", new {message = "Эта страница уже прикреплена к одному из аккаунтов"});
     var asset = new Asset
     {
         Category = category,
         CreateDate = DateTime.Now,
         IsDeleted = false,
         JsonData = jsonData.Data,
         FollowersCount = jsonData.Followers,
         User = user,
         Url = jsonData.Url,
         Title = jsonData.Title
     };
     _assetRepository.Add(asset);
     return RedirectToAction("MyAccounts");
 }
예제 #2
0
 public void Add(Asset asset)
 {
     _dbContext.Asset.Add(asset);
     _dbContext.SaveChanges();
 }