Beispiel #1
0
        private MakerEquipment SetUpMakerEquipment(MakerEquipmentDto entry, DBModels.Profile profile)
        {
            MakerEquipment dbEntry = _mapper.Map <MakerEquipment>(entry);

            dbEntry.Profile = profile;
            if (dbEntry.Id > 0)
            {
                _context.Entry(dbEntry).State = EntityState.Modified;
            }
            else
            {
                _context.MakerEquipment.Add(dbEntry);
            }
            return(dbEntry);
        }
Beispiel #2
0
        /// <summary>
        ///     Processes the entries that need to be deleted. If there are existing transactions attributed to the Need it
        ///     modifies the quantity and considers it fulfilled.
        /// </summary>
        /// <param name="ids">The ids to delete.</param>
        /// <param name="profile">The profile.</param>
        protected void ProcessDeletions(IQueryable <Need> needs, Profile profile)
        {
            // No transactions? Simple deletion.
            var toDelete = needs.Where(e => !e.Transactions.Any());

            _context.Needs.RemoveRange(toDelete);

            // Transactions? Cap the quantity to the transaction total and mark fulfilled.
            var toFulfill = needs.Where(e => e.Transactions.Any());

            foreach (var entry in toFulfill)
            {
                entry.Quantity              = entry.Transactions.Sum(e => e.Amount);
                entry.FulfilledDate         = DateTime.Now;
                _context.Entry(entry).State = EntityState.Modified;
            }
        }
Beispiel #3
0
        private Need SetUpNeed(NeedDto entry, Profile profile)
        {
            var dbEntry = _mapper.Map <Need>(entry);

            if (entry.ProfileId <= 0)
            {
                dbEntry.Profile = profile;
            }

            if (dbEntry.Id > 0)
            {
                _context.Entry(dbEntry).State = EntityState.Modified;
            }
            else
            {
                dbEntry.CreatedDate = System.DateTime.Now;
                _context.Needs.Add(dbEntry);
            }
            return(dbEntry);
        }