예제 #1
0
        public virtual int GetNextNumer(int iddlatabeli)
        {
            int    _statushistId = 0;
            string LastMessage   = string.Empty;

            try
            {
                IHP_NUMERACJA numerpoz = _entities.IHP_NUMERACJA.FirstOrDefault(x => x.ID_TABELA == iddlatabeli);
                numerpoz.NUMER++;
                _statushistId = numerpoz.NUMER;
                //    _entities.IHP_NUMERACJA.Add(numerpoz);
                _entities.Entry(numerpoz).State = EntityState.Modified;
                _entities.SaveChanges();
            }

            catch (Exception ex)
            {
                if (LastMessage == String.Empty)
                {
                    LastMessage = ex.InnerException.ToString();
                }
                LogManager.WriteLogMessage(LogManager.LogType.Error, LastMessage);
            }
            return(_statushistId);
        }
예제 #2
0
        private void SavaToDatabase()
        {
            string LastMessage;

            try
            {
                IHP_NUMERACJA numerkr = GetId(15);
                if (numerkr != null)
                {
                    numerkr.NUMER++;
                }

                IHP_FOTO fototodel = context.IHP_FOTO?.FirstOrDefault(x => x.ID_IHP_KARTOTEKA == _idwazenie && x.LP == nrkamery);

                if (fototodel != null)
                {
                    context.Entry(fototodel).State = EntityState.Deleted;
                    context.IHP_FOTO.Remove(fototodel);
                    context.SaveChanges();
                }

                IHP_FOTO foto = new IHP_FOTO()
                {
                    ID_IHP_FOTO      = numerkr.NUMER,
                    ID_IHP_KARTOTEKA = _idwazenie, //  zmienione
                    LP       = nrkamery,           // zmienione
                    NAMEFILE = _filename
                };
                context.IHP_NUMERACJA.Add(numerkr);
                context.Entry(numerkr).State = EntityState.Modified;
                context.IHP_FOTO.Add(foto);
                context.SaveChanges();
                Messenger.Default.Send <int>(3);
                InProcess = false;
            }
            catch (DbEntityValidationException e)
            {
                foreach (var eve in e.EntityValidationErrors)
                {
                    LogManager.WriteLogMessage(LogManager.LogType.Error, String.Format("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State));
                    foreach (var ve in eve.ValidationErrors)
                    {
                        LogManager.WriteLogMessage(LogManager.LogType.Error, String.Format("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage));
                    }
                }
                InProcess = false;
                throw;
            }
        }