public object Post(PostAsset request) { ApiUser hdUser = request.ApiUser; Instance_Config config = CheckAssets(hdUser); int account_id = request.account_id; if (request.location_id > 0 && config.LocationTracking && config.AccountManager) { string account_name = ""; if (account_id == 0) { account_id = hdUser.AccountId; account_name = hdUser.AccountName; } else { account_name = Models.Account_Details.GetAccountDetails(hdUser, request.account_id > 0 ? request.account_id : hdUser.AccountId, false).Name; } var location = Models.Location.GetLocation(hdUser.OrganizationId, hdUser.DepartmentId, request.location_id); if (account_id == -1) { account_id = 0; } if (location.AccountId != account_id) { throw new HttpError($"Cannot insert Asset to LocationId = {request.location_id}! This location don't exists in Account: {account_name} with Account Id: {account_id}."); } } int CreatedAssetID = Models.Assets.AddAsset(hdUser, request.serial_number, request.category_id, request.type_id, request.make_id, request.model_id, request.unique1_value, request.unique2_value, request.unique3_value, request.unique4_value, request.unique5_value, request.unique6_value, request.unique7_value, request.unique_motherboard, request.unique_bios, request.name, request.description, request.location_id, request.status_id, request.is_bulk, request.is_force_dublicate, request.checkout_id, request.note, request.entered_date); return(new HttpResult(CreatedAssetID, HttpStatusCode.OK)); }
public async Task <IActionResult> EditPostAsset(PostAssetViewModel assetvm) { string returnurl = assetvm.ReturnUrl; var postAsset = new PostAsset { Id = assetvm.Id, Caption = assetvm.Caption, }; if (assetvm.Asset == null) { postAsset.Asset = assetvm.CurrentAsset; } else { if (!string.IsNullOrEmpty(assetvm.CurrentAsset)) { _fileManager.RemovePostAsset(assetvm.CurrentAsset); } postAsset.Asset = _fileManager.SavePostAsset(assetvm.Asset); } if (postAsset.Id > 0) { _repo.UpdatePostAsset(postAsset); } else { var post = _repo.GetPostForAssets(assetvm.PostId); postAsset.Post = post; _repo.AddPostAsset(postAsset); } if (await _repo.SaveChangesAsync()) { return(LocalRedirect(returnurl)); } else { return(View(postAsset)); } }
public async Task <bool> AddAsync(CrawledPostDto model) { _sqlConnection.Open(); var transaction = await _sqlConnection.BeginTransactionAsync(); try { var post = new Post(); post.UpdateWith(model); post.InsertDateMi = DateTime.Now; post.InsertDateSh = PersianDateTime.Now.ToString(PersianDateTimeFormat.Date); var postId = _sqlConnection.ExecuteSpCommand <int>("[Instagram].[InsertPost]", new { Post = post.ToTableValuedParameter("[dbo].[Tvp_Post]") }, transaction).FirstOrDefault(); if (postId <= 0) { return(false); } if (!model.IsAlbum) { var postAsset = new PostAsset(); postAsset.UpdateWith(model); postAsset.PostId = postId; postAsset.InsertDateMi = DateTime.Now; postAsset.InsertDateSh = PersianDateTime.Now.ToString(PersianDateTimeFormat.Date); await _sqlConnection.ExecuteSpCommandAsync <int>("[Instagram].[InsertPostAsset]", new { PostAsset = postAsset.ToTableValuedParameter("[dbo].[Tvp_PostAsset]") }, transaction); } else { var postAssetList = new List <PostAsset>(); foreach (var item in model.Items) { var postAsset = new PostAsset(); postAsset.UpdateWith(item); postAsset.PostId = postId; postAsset.InsertDateMi = DateTime.Now; postAsset.InsertDateSh = PersianDateTime.Now.ToString(PersianDateTimeFormat.Date); postAssetList.Add(postAsset); } await _sqlConnection.ExecuteSpCommandAsync <int>("[Instagram].[InsertPostAsset]", new { PostAsset = postAssetList.ToTableValuedParameter("[dbo].[Tvp_PostAsset]") }, transaction); } transaction.Commit(); _sqlConnection.Close(); return(true); } catch (Exception e) { FileLoger.Error(e); transaction.Rollback(); _sqlConnection.Close(); if (e.Message.Contains("unique index")) { return(true); } return(false); } }
public void UpdatePostAsset(PostAsset postAsset) { _ctx.PostAssets.Update(postAsset); }
public void AddPostAsset(PostAsset postAsset) { _ctx.PostAssets.Add(postAsset); }