Exemplo n.º 1
0
        /// <summary>
        /// 引数に指定したDtDeliveryFileをDT_DELIVERY_FILEテーブルへ登録する
        /// </summary>
        /// <param name="inData">登録するデータ</param>
        /// <returns>処理結果</returns>
        public DtDeliveryFile CreateDtDeliveryFile(DtDeliveryFile inData)
        {
            DtDeliveryFile model = null;

            try
            {
                _logger.EnterJson("{0}", inData);

                DBAccessor.Models.DtDeliveryFile entity = new DBAccessor.Models.DtDeliveryFile(inData);

                _dbPolly.Execute(() =>
                {
                    DateTime createdAt = _timePrivder.UtcNow;

                    entity.CreateDatetime = createdAt;
                    entity.UpdateDatetime = createdAt;
                    foreach (DBAccessor.Models.DtDeliveryModel child in entity.DtDeliveryModel)
                    {
                        child.CreateDatetime = createdAt;
                    }

                    using (DBAccessor.Models.RmsDbContext db = new DBAccessor.Models.RmsDbContext(_appSettings))
                    {
                        var dbdata = db.DtDeliveryFile.Add(entity).Entity;
                        db.SaveChanges();
                        model = dbdata.ToModel();
                    }
                });

                return(model);
            }
            catch (ValidationException e)
            {
                throw new RmsParameterException(e.ValidationResult.ErrorMessage, e);
            }
            catch (Exception e)
            {
                throw new RmsException("DT_DELIVERY_FILEテーブルへのInsertに失敗しました。", e);
            }
            finally
            {
                _logger.LeaveJson("{0}", model);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// DT_DELIVERY_FILEテーブルからDtDeliveryFileを取得する
        /// </summary>
        /// <param name="sid">取得するデータのSID</param>
        /// <returns>取得したデータ</returns>
        public DtDeliveryFile ReadDtDeliveryFile(long sid)
        {
            DtDeliveryFile model = null;

            try
            {
                _logger.Enter($"{nameof(sid)}={sid}");

                DBAccessor.Models.DtDeliveryFile entity = null;
                _dbPolly.Execute(() =>
                {
                    using (DBAccessor.Models.RmsDbContext db = new DBAccessor.Models.RmsDbContext(_appSettings))
                    {
                        entity = db.DtDeliveryFile
                                 .Include(x => x.DeliveryFileTypeS)
                                 .Include(x => x.DtDeliveryModel)
                                 .FirstOrDefault(x => x.Sid == sid);
                    }
                });

                if (entity != null)
                {
                    model = entity.ToModel();
                }

                return(model);
            }
            catch (ValidationException e)
            {
                throw new RmsParameterException(e.ValidationResult.ErrorMessage, e);
            }
            catch (Exception e)
            {
                throw new RmsException("DT_DELIVERY_FILEテーブルのSelectに失敗しました。", e);
            }
            finally
            {
                _logger.LeaveJson("{0}", model);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// DT_DELIVERY_FILEテーブルからDtDeliveryFileを削除する
        /// </summary>
        /// <param name="sid">削除するデータのSID</param>
        /// <param name="rowVersion">rowversion</param>
        /// <returns>削除したデータ</returns>
        public DtDeliveryFile DeleteDtDeliveryFile(long sid, byte[] rowVersion)
        {
            DtDeliveryFile model = null;

            try
            {
                _logger.Enter($"{nameof(sid)}={sid} {nameof(rowVersion)}={rowVersion}");

                DBAccessor.Models.DtDeliveryFile entity = new DBAccessor.Models.DtDeliveryFile()
                {
                    Sid = sid, RowVersion = rowVersion
                };
                _dbPolly.Execute(() =>
                {
                    using (DBAccessor.Models.RmsDbContext db = new DBAccessor.Models.RmsDbContext(_appSettings))
                    {
                        // 指定した配信ファイルSIDを持つ配信グループを検索し、そのすべての配信ステータスが未配信状態であるかチェックする
                        // 備考:配信ファイルSIDを持つ配信グループが0個(Whereの結果が空のリスト)の場合、Allは必ずtrueを返す
                        //       そのためすべての配信ステータスが未配信状態であると見なされ、isAllNotStarted=trueとなることに注意
                        var isAllNotStarted = db.DtDeliveryGroup
                                              .Where(x => x.DeliveryFileSid == sid)
                                              .Include(x => x.DeliveryGroupStatusS)
                                              .All(x => x.DeliveryGroupStatusS.Code.Equals(Utility.Const.DeliveryGroupStatus.NotStarted));
                        if (!isAllNotStarted)
                        {
                            throw new RmsCannotChangeDeliveredFileException(string.Format("配信前状態ではないDT_DELIVERY_FILEテーブルのレコードをDeleteしようとしました。(DT_DELIVERY_FILE.SID = {0})", sid));
                        }

                        // SIDが一致するレコードが存在しない場合はDeleteを実行しない
                        // (存在しないSIDに対してDeleteを実行してしまうと、DbUpdateConcurrencyExceptionが発生してしまい、
                        //  RowVersion競合とNotFoundとの区別ができないため)
                        if (db.DtDeliveryFile.Any(x => x.Sid == sid))
                        {
                            db.DtDeliveryFile.Attach(entity);
                            db.DtDeliveryFile.Remove(entity);

                            if (db.SaveChanges() > 0)
                            {
                                model = entity.ToModel();
                            }
                        }
                    }
                });

                return(model);
            }
            catch (DbUpdateConcurrencyException e)
            {
                // RowVersion衝突が起きた
                throw new RmsConflictException("DT_DELIVERY_FILEテーブルのDeleteで競合が発生しました。", e);
            }
            catch (RmsException)
            {
                throw;
            }
            catch (Exception e)
            {
                throw new RmsException("DT_DELIVERY_FILEテーブルのDeleteに失敗しました。", e);
            }
            finally
            {
                _logger.LeaveJson("{0}", model);
            }
        }