Example #1
0
 public void UpdateHolder(Guid holderId, Holder holderData)
 {
     using (var context = new BaseInfoDbContext(_connectionString))
     {
         context.Holders.Update(holderData);
         context.Entry(holderData).State = EntityState.Modified;
         context.SaveChanges();
     }
 }
Example #2
0
        public void AddHolder(Holder holder)
        {
            using (var context = new BaseInfoDbContext(_connectionString))
            {
                if (context.Holders.Any(m => m.Moniker == holder.Moniker))
                {
                    throw new MonikerIsAlreadyExistException("Could not to add new hoilder with this moniker", holder.Moniker);
                }

                context.Holders.Add(holder);
                context.SaveChanges();
            }
        }
Example #3
0
        public void DeleteHolder(string moniker)
        {
            using (var context = new BaseInfoDbContext(_connectionString))
            {
                var holderToRemove = GetHolder(moniker);

                if (holderToRemove != null)
                {
                    context.Remove(holderToRemove);
                    context.Holders.Remove(holderToRemove);
                    context.SaveChanges();
                }
            }
        }
Example #4
0
        public void UpdateHolder(Holder holderData)
        {
            // Check input value
            if (holderData == null)
            {
                _logger.AddError("HolderData is null when call UpdateHolder method");
                throw new ArgumentNullException("holderData", "HolderData is null when call UpdateHolder method");
            }

            //  Get current holder We need to update
            var holder = GetHolder(holderData.Id);

            // Check existing current holder
            if (holder == null)
            {
                _logger.AddError("Cannot to get holder for update");
                throw new ArgumentNullException("holder", "Holder is null while update!");
            }

            try
            {
                using (var context = new BaseInfoDbContext(_connectionString))
                {
                    holder.CheckForRemove(holderData, context);
                    holder = holderData;
                    context.Update(holder);
                    context.SaveChanges();
                }
            }
            catch (NullReferenceException ex)
            {
                _logger.AddError("Issue with updating holder");
                _logger.AddError(ex.Message);
                throw new NullReferenceException("Cannot to update holder", ex);
            }
        }