public static OfferDto CreateNew(RioDbContext dbContext, int postingID, OfferUpsertDto offerUpsertDto) { if (!offerUpsertDto.TradeID.HasValue) { var trade = Trade.CreateNew(dbContext, postingID, offerUpsertDto.CreateAccountID); offerUpsertDto.TradeID = trade.TradeID; } var offer = new Offer { TradeID = offerUpsertDto.TradeID.Value, OfferNotes = offerUpsertDto.OfferNotes, CreateAccountID = offerUpsertDto.CreateAccountID, OfferDate = DateTime.UtcNow, Price = offerUpsertDto.Price, Quantity = offerUpsertDto.Quantity, OfferStatusID = offerUpsertDto.OfferStatusID }; dbContext.Offer.Add(offer); dbContext.SaveChanges(); dbContext.Entry(offer).Reload(); return(GetByOfferID(dbContext, offer.OfferID)); }
public static UserDto UpdateUserEntity(RioDbContext dbContext, int userID, UserUpsertDto userEditDto) { if (!userEditDto.RoleID.HasValue) { return(null); } var user = dbContext.User .Include(x => x.Role) .Single(x => x.UserID == userID); if (user.RoleID != (int)RoleEnum.Admin && userEditDto.RoleID == (int)RoleEnum.Admin) { dbContext.AccountUser.RemoveRange(dbContext.AccountUser.Where(x => x.UserID == user.UserID)); } user.RoleID = userEditDto.RoleID.Value; user.ReceiveSupportEmails = userEditDto.RoleID.Value == 1 && userEditDto.ReceiveSupportEmails; user.UpdateDate = DateTime.UtcNow; dbContext.SaveChanges(); dbContext.Entry(user).Reload(); return(GetByUserID(dbContext, userID)); }
public static WaterYearDto Finalize(RioDbContext dbContext, int waterYearID) { var waterYear = dbContext.WaterYear.Single(x => x.WaterYearID == waterYearID); waterYear.FinalizeDate = DateTime.UtcNow; dbContext.SaveChanges(); dbContext.Entry(waterYear).Reload(); return(GetByWaterYearID(dbContext, waterYearID)); }
public static TradeDto Update(RioDbContext dbContext, int tradeID, TradeStatusEnum tradeStatusEnum) { var trade = dbContext.Trade .Single(x => x.TradeID == tradeID); trade.TradeStatusID = (int)tradeStatusEnum; dbContext.SaveChanges(); dbContext.Entry(trade).Reload(); return(GetByTradeID(dbContext, tradeID)); }
public static UserDto UpdateUserGuid(RioDbContext dbContext, int userID, Guid userGuid) { var user = dbContext.User .Single(x => x.UserID == userID); user.UserGuid = userGuid; user.UpdateDate = DateTime.UtcNow; dbContext.SaveChanges(); dbContext.Entry(user).Reload(); return(GetByUserID(dbContext, userID)); }
public static UserDto SetDisclaimerAcknowledgedDate(RioDbContext dbContext, int userID) { var user = dbContext.User.Single(x => x.UserID == userID); user.UpdateDate = DateTime.UtcNow; user.DisclaimerAcknowledgedDate = DateTime.UtcNow; dbContext.SaveChanges(); dbContext.Entry(user).Reload(); return(GetByUserID(dbContext, userID)); }
public static OpenETSyncHistoryDto UpdateSyncResultByID(RioDbContext rioDbContext, int openETSyncHistoryID, OpenETSyncResultTypeEnum resultType) { var openETSyncHistory = rioDbContext.OpenETSyncHistory.Single(x => x.OpenETSyncHistoryID == openETSyncHistoryID); openETSyncHistory.UpdateDate = DateTime.UtcNow; openETSyncHistory.OpenETSyncResultTypeID = (int)resultType; rioDbContext.SaveChanges(); rioDbContext.Entry(openETSyncHistory).Reload(); return(GetByOpenETSyncHistoryID(rioDbContext, openETSyncHistory.OpenETSyncHistoryID)); }
public static WaterTransferDto ChangeWaterRegistrationStatus(RioDbContext dbContext, int waterTransferID, WaterTransferRegistrationDto waterTransferRegistrationDto, WaterTransferRegistrationStatusEnum waterTransferRegistrationStatusEnum) { var waterTransferRegistration = dbContext.WaterTransferRegistration .Single(x => x.WaterTransferID == waterTransferID && x.WaterTransferTypeID == waterTransferRegistrationDto.WaterTransferTypeID); waterTransferRegistration.WaterTransferRegistrationStatusID = (int)waterTransferRegistrationStatusEnum; waterTransferRegistration.StatusDate = DateTime.Now; dbContext.SaveChanges(); dbContext.Entry(waterTransferRegistration).Reload(); return(GetByWaterTransferID(dbContext, waterTransferID)); }
public static PostingDto UpdateStatus(RioDbContext dbContext, int postingID, PostingUpdateStatusDto postingUpdateStatusDto, int?availableQuantity) { var posting = dbContext.Posting .Single(x => x.PostingID == postingID); posting.PostingStatusID = postingUpdateStatusDto.PostingStatusID; if (availableQuantity.HasValue) { posting.AvailableQuantity = availableQuantity.Value; } dbContext.SaveChanges(); dbContext.Entry(posting).Reload(); return(GetByPostingID(dbContext, postingID)); }
public static OpenETSyncHistoryDto New(RioDbContext dbContext, int year) { var openETSyncHistoryToAdd = new OpenETSyncHistory() { OpenETSyncResultTypeID = (int)OpenETSyncResultTypeEnum.InProgress, WaterYearID = dbContext.WaterYear.Single(x => x.Year == year).WaterYearID, CreateDate = DateTime.UtcNow, UpdateDate = DateTime.UtcNow }; dbContext.OpenETSyncHistory.Add(openETSyncHistoryToAdd); dbContext.SaveChanges(); dbContext.Entry(openETSyncHistoryToAdd).Reload(); return(GetByOpenETSyncHistoryID(dbContext, openETSyncHistoryToAdd.OpenETSyncHistoryID)); }
public static WaterTransferDto CreateNew(RioDbContext dbContext, OfferDto offerDto, TradeDto tradeDto, PostingDto postingDto) { var waterTransfer = new WaterTransfer { OfferID = offerDto.OfferID, AcreFeetTransferred = offerDto.Quantity, TransferDate = offerDto.OfferDate }; var waterTransferRegistrationBuyer = new WaterTransferRegistration() { WaterTransfer = waterTransfer, WaterTransferTypeID = (int)WaterTransferTypeEnum.Buying, StatusDate = DateTime.Now, WaterTransferRegistrationStatusID = (int)WaterTransferRegistrationStatusEnum.Pending }; var waterTransferRegistrationSeller = new WaterTransferRegistration() { WaterTransfer = waterTransfer, WaterTransferTypeID = (int)WaterTransferTypeEnum.Selling, StatusDate = DateTime.Now, WaterTransferRegistrationStatusID = (int)WaterTransferRegistrationStatusEnum.Pending }; if (postingDto.PostingType.PostingTypeID == (int)PostingTypeEnum.OfferToSell) { waterTransferRegistrationSeller.AccountID = postingDto.CreateAccount.AccountID; waterTransferRegistrationBuyer.AccountID = tradeDto.CreateAccount.AccountID; } else { waterTransferRegistrationSeller.AccountID = tradeDto.CreateAccount.AccountID; waterTransferRegistrationBuyer.AccountID = postingDto.CreateAccount.AccountID; } dbContext.WaterTransfer.Add(waterTransfer); dbContext.WaterTransferRegistration.Add(waterTransferRegistrationBuyer); dbContext.WaterTransferRegistration.Add(waterTransferRegistrationSeller); dbContext.SaveChanges(); dbContext.Entry(waterTransfer).Reload(); return(GetByWaterTransferID(dbContext, waterTransfer.WaterTransferID)); }
public static TradeDto CreateNew(RioDbContext dbContext, int postingID, int accountID) { var trade = new Trade { PostingID = postingID, CreateAccountID = accountID, TradeDate = DateTime.UtcNow, TradeStatusID = (int)TradeStatusEnum.Countered }; // we need to calculate the trade number var existingTradesForTheYearCount = dbContext.Trade.AsNoTracking().Count(x => x.TradeDate.Year == trade.TradeDate.Year); trade.TradeNumber = $"{trade.TradeDate.Year}-{existingTradesForTheYearCount + 1:D4}"; dbContext.Trade.Add(trade); dbContext.SaveChanges(); dbContext.Entry(trade).Reload(); return(GetByTradeID(dbContext, trade.TradeID)); }
public static PostingDto CreateNew(RioDbContext dbContext, PostingUpsertDto postingUpsertDto) { var posting = new Posting { PostingTypeID = postingUpsertDto.PostingTypeID, PostingDescription = postingUpsertDto.PostingDescription, CreateAccountID = postingUpsertDto.CreateAccountID, CreateUserID = postingUpsertDto.CreateUserID, PostingDate = DateTime.UtcNow, Price = postingUpsertDto.Price, Quantity = postingUpsertDto.Quantity, AvailableQuantity = postingUpsertDto.Quantity, PostingStatusID = (int)PostingStatusEnum.Open }; dbContext.Posting.Add(posting); dbContext.SaveChanges(); dbContext.Entry(posting).Reload(); return(GetByPostingID(dbContext, posting.PostingID)); }
public static AccountDto CreateAccountEntity(RioDbContext dbContext, AccountUpdateDto accountUpdateDto, string rioConfigurationVerificationKeyChars) { var account = new Account() { AccountStatusID = accountUpdateDto.AccountStatusID, Notes = accountUpdateDto.Notes, AccountName = accountUpdateDto.AccountName, UpdateDate = DateTime.UtcNow, CreateDate = DateTime.UtcNow, InactivateDate = accountUpdateDto.AccountStatusID == (int)AccountStatusEnum.Inactive ? DateTime.UtcNow : (DateTime?)null, AccountVerificationKey = accountUpdateDto.AccountStatusID == (int)AccountStatusEnum.Inactive ? null : GenerateAndVerifyAccountVerificationKey(rioConfigurationVerificationKeyChars, GetCurrentAccountVerificationKeys(dbContext)) }; dbContext.Account.Add(account); dbContext.SaveChanges(); dbContext.Entry(account).Reload(); return(GetByAccountID(dbContext, account.AccountID)); }
public static AccountDto UpdateAccountEntity(RioDbContext dbContext, int accountID, AccountUpdateDto accountUpdateDto, string rioConfigurationVerificationKeyChars) { var account = dbContext.Account .Include(x => x.AccountStatus) .Single(x => x.AccountID == accountID); account.AccountStatusID = accountUpdateDto.AccountStatusID; account.InactivateDate = accountUpdateDto.AccountStatusID == (int)AccountStatusEnum.Inactive ? DateTime.UtcNow : (DateTime?)null; account.AccountVerificationKey = accountUpdateDto.AccountStatusID == (int)AccountStatusEnum.Inactive ? null : account.AccountVerificationKey ?? (GenerateAndVerifyAccountVerificationKey(rioConfigurationVerificationKeyChars, GetCurrentAccountVerificationKeys(dbContext))); account.AccountName = accountUpdateDto.AccountName; account.UpdateDate = DateTime.UtcNow; dbContext.SaveChanges(); dbContext.Entry(account).Reload(); return(GetByAccountID(dbContext, accountID)); }
public static UserDto CreateNewUser(RioDbContext dbContext, UserUpsertDto userToCreate, string loginName, Guid userGuid) { if (!userToCreate.RoleID.HasValue) { return(null); } var user = new User { UserGuid = userGuid, LoginName = loginName, Email = userToCreate.Email, FirstName = userToCreate.FirstName, LastName = userToCreate.LastName, RoleID = userToCreate.RoleID.Value, CreateDate = DateTime.UtcNow, }; dbContext.User.Add(user); dbContext.SaveChanges(); dbContext.Entry(user).Reload(); return(GetByUserID(dbContext, user.UserID)); }