Exemplo n.º 1
0
        public static int BulkSetAllocation(RioDbContext dbContext, ParcelAllocationUpsertDto parcelAllocationUpsertDto)
        {
            // delete existing parcel allocations
            var existingParcelAllocations = dbContext.ParcelAllocation.Where(x => x.WaterYear == parcelAllocationUpsertDto.WaterYear && x.ParcelAllocationTypeID == parcelAllocationUpsertDto.ParcelAllocationTypeID);

            if (existingParcelAllocations.Any())
            {
                dbContext.ParcelAllocation.RemoveRange(existingParcelAllocations);
                dbContext.SaveChanges();
            }

            var parcels = dbContext.Parcel.AsNoTracking().OrderBy(x => x.ParcelID).ToList();

            foreach (var parcel in parcels)
            {
                var parcelAllocation = new ParcelAllocation
                {
                    ParcelID  = parcel.ParcelID,
                    WaterYear = parcelAllocationUpsertDto.WaterYear,
                    ParcelAllocationTypeID = parcelAllocationUpsertDto.ParcelAllocationTypeID,
                    AcreFeetAllocated      = parcelAllocationUpsertDto.AcreFeetAllocated * (decimal)parcel.ParcelAreaInAcres
                };
                dbContext.ParcelAllocation.Add(parcelAllocation);
            }
            dbContext.SaveChanges();
            return(parcels.Count);
        }
Exemplo n.º 2
0
        //Keep as reference for setting Allocation proportionally across an account and by volume
        //public static void BulkSetAllocation(RioDbContext dbContext, List<BulkSetAllocationCSV> records, int waterYear, int parcelAllocationType)
        //{
        //    // delete existing parcel allocations
        //    var existingParcelAllocations = dbContext.ParcelAllocation.Where(x =>
        //        x.WaterYear == waterYear && x.ParcelAllocationTypeID == parcelAllocationType);
        //    if (existingParcelAllocations.Any())
        //    {
        //        dbContext.ParcelAllocation.RemoveRange(existingParcelAllocations);
        //        dbContext.SaveChanges();
        //    }

        //    // select parcels owned by accounts from upload and group by accounts to associate allocation volumes with list of parcels
        //    var accountAllocationVolumes = Parcel.AccountParcelWaterYearOwnershipsByYear(dbContext, waterYear).ToList().GroupBy(x => x.Account.AccountNumber)
        //        .Where(x => records.Select(y => y.AccountNumber).Contains(x.Key)).Join(records,
        //            account => account.Key, record => record.AccountNumber,
        //            (x, y) => new { Parcels = x.Select(z => z.Parcel).ToList(), y.AllocationVolume });


        //    var parcelAllocations = new List<ParcelAllocation>();
        //    // apportion the reconciliation volumes to their lists of parcels by area percentage
        //    foreach (var record in accountAllocationVolumes)
        //    {
        //        var parcels = record.Parcels;
        //        var sum = parcels.Sum(x => x.ParcelAreaInAcres);
        //        parcelAllocations.AddRange(parcels.Select(x => new ParcelAllocation()
        //        {
        //            ParcelID = x.ParcelID,
        //            AcreFeetAllocated =
        //                (decimal)(record.AllocationVolume * (x.ParcelAreaInAcres / sum)),
        //            WaterYear = waterYear,
        //            ParcelAllocationTypeID = parcelAllocationType
        //        }));
        //    }

        //    dbContext.ParcelAllocation.AddRange(parcelAllocations);
        //    dbContext.SaveChanges();
        //}

        public static void BulkSetAllocation(RioDbContext dbContext, List <BulkSetAllocationCSV> records, int waterYear,
                                             int parcelAllocationType)
        {
            //delete existing parcel allocations
            var existingParcelAllocations = dbContext.ParcelAllocation.Where(x =>
                                                                             x.WaterYear == waterYear && x.ParcelAllocationTypeID == parcelAllocationType);

            if (existingParcelAllocations.Any())
            {
                dbContext.ParcelAllocation.RemoveRange(existingParcelAllocations);
                dbContext.SaveChanges();
            }

            var parcelAllocations = new List <ParcelAllocation>();

            foreach (var record in records)
            {
                var parcel = dbContext.Parcel.First(x => x.ParcelNumber == record.APN);
                parcelAllocations.Add(new ParcelAllocation()
                {
                    ParcelID          = parcel.ParcelID,
                    AcreFeetAllocated =
                        (decimal)(record.AllocationQuantity * parcel.ParcelAreaInAcres),
                    WaterYear = waterYear,
                    ParcelAllocationTypeID = parcelAllocationType
                });
            }

            dbContext.ParcelAllocation.AddRange(parcelAllocations);
            dbContext.SaveChanges();
        }
Exemplo n.º 3
0
        public static List <ParcelAllocationDto> Upsert(RioDbContext dbContext, int parcelID, List <ParcelAllocationUpsertDto> parcelAllocationUpsertDtos)
        {
            // delete existing parcel allocations
            var existingParcelAllocations = dbContext.ParcelAllocation.Where(x => x.ParcelID == parcelID);

            if (existingParcelAllocations.Any())
            {
                dbContext.ParcelAllocation.RemoveRange(existingParcelAllocations);
                dbContext.SaveChanges();
            }

            foreach (var parcelAllocationUpsertDto in parcelAllocationUpsertDtos)
            {
                var parcelAllocation = dbContext.ParcelAllocation
                                       .SingleOrDefault(x => x.ParcelID == parcelID && x.WaterYear == parcelAllocationUpsertDto.WaterYear && x.ParcelAllocationTypeID == parcelAllocationUpsertDto.ParcelAllocationTypeID);

                if (parcelAllocation == null)
                {
                    parcelAllocation = new ParcelAllocation
                    {
                        ParcelID  = parcelID,
                        WaterYear = parcelAllocationUpsertDto.WaterYear,
                        ParcelAllocationTypeID = parcelAllocationUpsertDto.ParcelAllocationTypeID
                    };
                    dbContext.ParcelAllocation.Add(parcelAllocation);
                }

                parcelAllocation.AcreFeetAllocated = parcelAllocationUpsertDto.AcreFeetAllocated;
            }
            dbContext.SaveChanges();

            return(ListByParcelID(dbContext, parcelID));
        }
        public static IEnumerable <WaterTransferRegistrationParcelDto> SaveParcels(RioDbContext dbContext, int waterTransferID, WaterTransferRegistrationDto waterTransferRegistrationDto)
        {
            // get the registration record
            var waterTransferRegistration = dbContext.WaterTransferRegistration.Single(x =>
                                                                                       x.WaterTransferID == waterTransferID && x.WaterTransferTypeID == waterTransferRegistrationDto.WaterTransferTypeID);

            // delete existing parcels registered
            var existingWaterTransferRegistrationParcels = dbContext.WaterTransferRegistrationParcel.Where(x => x.WaterTransferRegistrationID == waterTransferRegistration.WaterTransferRegistrationID);

            if (existingWaterTransferRegistrationParcels.Any())
            {
                dbContext.WaterTransferRegistrationParcel.RemoveRange(existingWaterTransferRegistrationParcels);
                dbContext.SaveChanges();
            }

            foreach (var waterTransferParcelDto in waterTransferRegistrationDto.WaterTransferRegistrationParcels)
            {
                var waterTransferRegistrationParcel = new WaterTransferRegistrationParcel
                {
                    WaterTransferRegistrationID = waterTransferRegistration.WaterTransferRegistrationID,
                    ParcelID            = waterTransferParcelDto.ParcelID,
                    AcreFeetTransferred = waterTransferParcelDto.AcreFeetTransferred
                };
                dbContext.WaterTransferRegistrationParcel.Add(waterTransferRegistrationParcel);
            }

            dbContext.SaveChanges();
            return(ListByWaterTransferRegistrationID(dbContext, waterTransferRegistration.WaterTransferRegistrationID));
        }
Exemplo n.º 5
0
        public static void RemoveAssociatedAccount(RioDbContext dbContext, int userID, int accountID)
        {
            var currentAccountUser = dbContext.AccountUser.Single(x => x.UserID == userID && x.AccountID == accountID);

            dbContext.AccountUser.Remove(currentAccountUser);
            dbContext.SaveChanges();
        }
Exemplo n.º 6
0
        public static void BulkCreateWithListOfNames(RioDbContext dbContext, string rioConfigurationVerificationKeyChars, List <string> accountNamesToCreate)
        {
            var listOfAccountsToCreate         = new List <Account>();
            var currentAccountVerificationKeys = GetCurrentAccountVerificationKeys(dbContext);

            accountNamesToCreate.ForEach(x =>
            {
                var accountVerificationKey =
                    GenerateAndVerifyAccountVerificationKey(rioConfigurationVerificationKeyChars,
                                                            currentAccountVerificationKeys);
                currentAccountVerificationKeys.Add(accountVerificationKey);

                listOfAccountsToCreate.Add(new Account()
                {
                    AccountStatusID        = (int)AccountStatusEnum.Active,
                    AccountName            = x,
                    UpdateDate             = DateTime.UtcNow,
                    CreateDate             = DateTime.UtcNow,
                    AccountVerificationKey = accountVerificationKey
                });
            });

            dbContext.Account.AddRange(listOfAccountsToCreate);

            dbContext.SaveChanges();
        }
Exemplo n.º 7
0
        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));
        }
Exemplo n.º 8
0
        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));
        }
Exemplo n.º 9
0
        public static void Delete(RioDbContext dbContext, int postingID)
        {
            var posting = dbContext.Posting
                          .Single(x => x.PostingID == postingID);

            dbContext.Posting.Remove(posting);
            dbContext.SaveChanges();
        }
Exemplo n.º 10
0
        public static void DeleteByParcelID(RioDbContext dbContext, int parcelId)
        {
            var toRemove = dbContext.AccountReconciliation.Where(x => x.ParcelID == parcelId);

            dbContext.AccountReconciliation.RemoveRange(toRemove);

            dbContext.SaveChanges();
        }
Exemplo n.º 11
0
        public static void UpdateAccountVerificationKeyLastUsedDateForAccountIDs(RioDbContext dbContext, List <int> accountIDs)
        {
            var accounts = dbContext.Account.Where(x => accountIDs.Contains(x.AccountID)).ToList();

            accounts.ForEach(x => x.AccountVerificationKeyLastUseDate = DateTime.UtcNow);

            dbContext.SaveChanges();
        }
Exemplo n.º 12
0
        public static void UpdateParcelLayerUpdateDateForID(RioDbContext dbContext, int waterYearId)
        {
            var waterYear = dbContext.WaterYear.Single(x => x.WaterYearID == waterYearId);

            waterYear.ParcelLayerUpdateDate = DateTime.UtcNow;

            dbContext.SaveChanges();
        }
Exemplo n.º 13
0
        public static void UpdateParcelStatus(RioDbContext dbContext, int parcelID, int parcelStatusID)
        {
            var currentParcel = dbContext.Parcel.Single(x => x.ParcelID == parcelID);

            currentParcel.ParcelStatusID = parcelStatusID;
            currentParcel.InactivateDate = parcelStatusID == (int)ParcelStatusEnum.Active ? (DateTime?)null : DateTime.UtcNow;

            dbContext.SaveChanges();
        }
Exemplo n.º 14
0
        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));
        }
Exemplo n.º 15
0
        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));
        }
Exemplo n.º 16
0
        public static void BulkInactivate(RioDbContext dbContext, List <Account> accountsToInactivate)
        {
            accountsToInactivate.ForEach(x =>
            {
                x.UpdateDate             = DateTime.UtcNow;
                x.InactivateDate         = DateTime.UtcNow;
                x.AccountStatusID        = (int)AccountStatusEnum.Inactive;
                x.AccountVerificationKey = null;
            });

            dbContext.SaveChanges();
        }
Exemplo n.º 17
0
        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));
        }
Exemplo n.º 18
0
        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));
        }
Exemplo n.º 19
0
        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));
        }
Exemplo n.º 20
0
        public static CustomRichTextDto UpdateCustomRichText(RioDbContext dbContext, int customRichTextTypeID,
                                                             CustomRichTextDto customRichTextUpdateDto)
        {
            var customRichText = dbContext.CustomRichText
                                 .SingleOrDefault(x => x.CustomRichTextTypeID == customRichTextTypeID);

            // null check occurs in calling endpoint method.
            customRichText.CustomRichTextContent = customRichTextUpdateDto.CustomRichTextContent;

            dbContext.SaveChanges();

            return(customRichText.AsDto());
        }
Exemplo n.º 21
0
        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));
        }
Exemplo n.º 22
0
        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));
        }
Exemplo n.º 23
0
        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));
        }
Exemplo n.º 24
0
        public static void CreateParcelAllocationHistoryEntity(RioDbContext dbContext, int userID, int?fileResourceID, int waterYear, int parcelAllocationTypeID, decimal?allocated)
        {
            var parcelAllocationHistoryEntry = new ParcelAllocationHistory()
            {
                ParcelAllocationHistoryDate      = DateTime.Now,
                ParcelAllocationHistoryWaterYear = waterYear,
                ParcelAllocationTypeID           = parcelAllocationTypeID,
                UserID         = userID,
                FileResourceID = fileResourceID,
                ParcelAllocationHistoryValue =
                    fileResourceID != null ? (decimal?)null : allocated
            };

            dbContext.ParcelAllocationHistory.Add(parcelAllocationHistoryEntry);
            dbContext.SaveChanges();
        }
Exemplo n.º 25
0
        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));
        }
Exemplo n.º 26
0
        public static List <int> SetAssociatedAccounts(RioDbContext dbContext, int userID, List <int> accountIDs)
        {
            var newAccountUsers = accountIDs.Select(accountID => new AccountUser()
            {
                UserID = userID, AccountID = accountID
            }).ToList();

            var existingAccountUsers = dbContext.User.Include(x => x.AccountUser)
                                       .Single(x => x.UserID == userID).AccountUser;

            var addedAccountIDs = accountIDs.Where(x => !existingAccountUsers.Select(y => y.AccountID).Contains(x)).ToList();

            var allInDatabase = dbContext.AccountUser;

            existingAccountUsers.Merge(newAccountUsers, allInDatabase, (x, y) => x.UserID == y.UserID && x.AccountID == y.AccountID);

            dbContext.SaveChanges();

            return(addedAccountIDs);
        }
Exemplo n.º 27
0
        public static AccountDto SetAssociatedUsers(RioDbContext dbContext, AccountDto accountDto, List <int> userIDs, out List <int> addedUserIDs)
        {
            var newAccountUsers = userIDs.Select(userID => new AccountUser()
            {
                AccountID = accountDto.AccountID, UserID = userID
            }).ToList();

            var existingAccountUsers = dbContext.Account.Include(x => x.AccountUser)
                                       .Single(x => x.AccountID == accountDto.AccountID).AccountUser;

            addedUserIDs = userIDs.Where(x => !existingAccountUsers.Select(y => y.UserID).Contains(x)).ToList();

            var allInDatabase = dbContext.AccountUser;

            existingAccountUsers.Merge(newAccountUsers, allInDatabase, (x, y) => x.AccountID == y.AccountID && x.UserID == y.UserID);

            dbContext.SaveChanges();

            return(GetByAccountID(dbContext, accountDto.AccountID));
        }
Exemplo n.º 28
0
        public static int SaveParcelMonthlyUsageOverrides(RioDbContext dbContext, int accountID, int waterYear,
                                                          List <ParcelMonthlyEvapotranspirationDto> overriddenParcelMonthlyEvapotranspirationDtos)
        {
            var postedDtos = overriddenParcelMonthlyEvapotranspirationDtos.Where(x => !x.IsEmpty || (x.IsEmpty && x.OverriddenEvapotranspirationRate != null)).Select(x => new ParcelMonthlyEvapotranspiration()
            {
                ParcelID   = x.ParcelID,
                WaterYear  = x.WaterYear,
                WaterMonth = x.WaterMonth,
                //Don't write to EvapotranspirationRate. Only OpenET imports should adjust that data
                //EvapotranspirationRate = x.EvapotranspirationRate,
                OverriddenEvapotranspirationRate = x.OverriddenEvapotranspirationRate
            }).ToList();

            var parcelDtos = Parcel.ListByAccountIDAndYear(dbContext, accountID, waterYear).ToList();
            var parcelIDs  = parcelDtos.Select(x => x.ParcelID).ToList();

            var existingParcelMonthlyEvapotranspirationDtos =
                dbContext.ParcelMonthlyEvapotranspiration.Where(x =>
                                                                parcelIDs.Contains(x.ParcelID) && x.WaterYear == waterYear).ToList();

            var allInDatabase = dbContext.ParcelMonthlyEvapotranspiration;

            var countChanging = postedDtos.Count(x =>
                                                 existingParcelMonthlyEvapotranspirationDtos.Any(y =>
                                                                                                 y.ParcelID == x.ParcelID && y.WaterYear == x.WaterYear && y.WaterMonth == x.WaterMonth &&
                                                                                                 y.OverriddenEvapotranspirationRate != x.OverriddenEvapotranspirationRate));

            var countBeingIntroduced = postedDtos.Count(x =>
                                                        !existingParcelMonthlyEvapotranspirationDtos.Any(y =>
                                                                                                         y.ParcelID == x.ParcelID && y.WaterYear == x.WaterYear && y.WaterMonth == x.WaterMonth));

            var countBeingRemoved = existingParcelMonthlyEvapotranspirationDtos.Count(x =>
                                                                                      !postedDtos.Any(y =>
                                                                                                      y.ParcelID == x.ParcelID && y.WaterYear == x.WaterYear && y.WaterMonth == x.WaterMonth));

            existingParcelMonthlyEvapotranspirationDtos.Merge(postedDtos, allInDatabase,
                                                              (x, y) => x.ParcelID == y.ParcelID && x.WaterMonth == y.WaterMonth && x.WaterYear == y.WaterYear,
                                                              (x, y) => x.OverriddenEvapotranspirationRate = y.OverriddenEvapotranspirationRate);
            dbContext.SaveChanges();
            return(countChanging + countBeingIntroduced + countBeingRemoved);
        }
Exemplo n.º 29
0
        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));
        }
Exemplo n.º 30
0
        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));
        }