Exemplo n.º 1
0
        public virtual ActionResult UpdateWave(WaveEditorViewModel model)
        {
            if (!ModelState.IsValid)
            {
                PopulateWaveEditorViewModel(model);
                return(View(Views.WaveEditor, model));
            }
            var bucket = new BucketEditable
            {
                //BucketId = model.BucketId,
                BucketName = model.BucketName,
                //PriorityId = model.PriorityId,
                BucketComment        = model.BucketComment,
                QuickPitch           = model.QuickPitch,
                PitchLimit           = model.PitchLimit.Value,
                RequireBoxExpediting = model.RequiredBoxExpediting,
                PullAreaId           = model.PullAreaId,
                PitchAreaId          = model.PitchAreaId
            };

            try
            {
                using (var trans = _service.Value.BeginTransaction())
                {
                    _service.Value.UpdateWave(model.BucketId, bucket, trans);
                    if (model.UnfreezeWaveAfterSave)
                    {
                        //  if user says unfreeze bucket after editing.
                        _service.Value.UnfreezePickWave(model.BucketId, trans);
                    }

                    trans.Commit();
                }
                AddStatusMessage(string.Format("Pick Wave {0} updated.", model.BucketId));
            }
            catch (DbException ex)
            {
                ModelState.AddModelError("", "Pick wave could not be updated. Please review the error and try again");
                ModelState.AddModelError("", ex.Message);
                // return RedirectToAction(this.Actions.EditableWave(model.BucketId, SuggestedNextActionType.NotSet));
                return(RedirectToAction(this.Actions.WavePickslips(model.BucketId)));
            }
            catch (ValidationException ex)
            {
                ModelState.AddModelError("", ex.Message);
                //return RedirectToAction(this.Actions.EditableWave(model.BucketId, SuggestedNextActionType.NotSet));
                return(RedirectToAction(this.Actions.WavePickslips(model.BucketId)));
            }

            return(RedirectToAction(this.Actions.WavePickslips(model.BucketId)));
        }
 internal WaveEditorViewModel(BucketEditable entity)
 {
     this.BucketComment         = entity.BucketComment;
     this.BucketId              = entity.BucketId;
     this.BucketName            = entity.BucketName;
     this.CustomerId            = entity.CustomerId;
     this.PitchAreaId           = entity.PitchAreaId;
     this.PitchAreaShortName    = entity.PitchAreaShortName;
     this.PullAreaId            = entity.PullAreaId;
     this.PullAreaShortName     = entity.PullAreaShortName;
     this.PitchLimit            = entity.PitchLimit;
     this.QuickPitch            = entity.QuickPitch;
     this.RequiredBoxExpediting = entity.RequireBoxExpediting;
 }
Exemplo n.º 3
0
        /// <summary>
        /// Edit bucket property. Error if you attempt to edit an unfrozen wave. This should be called within a transaction so that the update can be cancelled
        /// if the wave is not frozen
        /// </summary>
        /// <param name="bucket"></param>
        /// <param name="trans">Required only to ensure that the caller has created a transaction</param>
        internal BucketEditable UpdateWave(int bucketId, BucketEditable bucket, DbTransaction trans)
        {
            if (bucket == null)
            {
                throw new ArgumentNullException("bucket");
            }

            var updatedWave = _repos.UpdateWave(bucketId, bucket);

            if (!bucket.IsFrozen)
            {
                throw new InvalidOperationException("Only frozen pick waves can be edited");
            }
            return(updatedWave);
        }
        public BucketEditable GetEditableBucket(int bucketId)
        {
            const string QUERY  = @"
                       SELECT     BKT.BUCKET_ID AS BUCKET_ID,
                                   BKT.NAME AS NAME,
                                   BKT.BUCKET_COMMENT AS BUCKET_COMMENT,
                                   BKT.PITCH_LIMIT AS PITCH_LIMIT,
                                   BKT.PITCH_IA_ID AS PITCH_AREA_ID,
                                  BKT.PULL_CARTON_AREA AS PULL_AREA_ID,
                                   (select max(customer_id) from ps p where p.bucket_id = bkt.bucket_id) AS CUSTOMER_ID,
                                   BKT.FREEZE AS FREEZE,
                                   CASE WHEN BKT.PITCH_TYPE = 'QUICK' THEN 'Y' END AS QUICK_PITCH_FLAG,
                                   BKT.PULL_TYPE AS PULL_TYPE   
                              FROM BUCKET BKT
                             WHERE BKT.BUCKET_ID = :BUCKET_ID";
            var          binder = SqlBinder.Create(row =>
            {
                var bucket = new BucketEditable
                {
                    BucketId             = row.GetInteger("BUCKET_ID").Value,
                    BucketName           = row.GetString("NAME"),
                    BucketComment        = row.GetString("BUCKET_COMMENT"),
                    PitchLimit           = row.GetInteger("PITCH_LIMIT") ?? 0,
                    IsFrozen             = row.GetString("FREEZE") == "Y",
                    CustomerId           = row.GetString("CUSTOMER_ID"),
                    PullAreaId           = row.GetString("PULL_AREA_ID"),
                    PitchAreaId          = row.GetString("PITCH_AREA_ID"),
                    QuickPitch           = row.GetString("QUICK_PITCH_FLAG") == "Y",
                    RequireBoxExpediting = row.GetString("PULL_TYPE") == "EXP"
                };
                return(bucket);
            }
                                                   );

            binder.Parameter("BUCKET_ID", bucketId);
            return(_db.ExecuteSingle(QUERY, binder));
        }
        /// <summary>
        /// Edit bucket property as Pull area , pitch area etc..
        /// </summary>
        /// <param name="bucket"></param>
        /// <param name="flags"> </param>
        /// <returns>Updated bucket values. If the passed bucket does not exist, returns null.</returns>
        /// <remarks>
        /// Throws an exception if the pick wave is not frozen
        /// </remarks>
        internal BucketEditable UpdateWave(int bucketId, BucketEditable bucket)
        {
            const string QUERY  = @"
                        UPDATE <proxy />BUCKET BKT
                            SET  BKT.NAME              = :NAME,           
                                 BKT.PITCH_IA_ID       = :PITCH_IA_ID,    
                                 BKT.BUCKET_COMMENT    = :BUCKET_COMMENT,                    
                                 BKT.PULL_CARTON_AREA  = :PULL_CARTON_AREA,  
                                 BKT.PULL_TYPE      = :PULL_TYPE,      
                                 BKT.PITCH_TYPE  = :PITCH_TYPE,       
                                 BKT.PITCH_LIMIT       = :PITCH_LIMIT,       
                                 BKT.DATE_MODIFIED = SYSDATE
                         WHERE BKT.BUCKET_ID = :BUCKET_ID
                        RETURNING BKT.NAME, 
                                  BKT.PITCH_IA_ID,
                                  BKT.BUCKET_COMMENT,
                                  BKT.PULL_CARTON_AREA,
                                  BKT.PULL_TYPE,
                                  BKT.PITCH_TYPE,
                                  BKT.PITCH_LIMIT,
BKT.FREEZE
                        INTO      :NAME_OUT,
                                  :PITCH_IA_ID_OUT,
                                  :BUCKET_COMMENT_OUT,
                                  :PULL_CARTON_AREA_OUT,
                                  :PULL_TYPE_OUT,
                                  :PITCH_TYPE_OUT,
                                  :PITCH_LIMIT_OUT,
:FREEZE_OUT
";
            var          binder = SqlBinder.Create();

            binder.Parameter("NAME", bucket.BucketName)
            .Parameter("PULL_CARTON_AREA", bucket.PullAreaId)
            .Parameter("PITCH_IA_ID", bucket.PitchAreaId)
            .Parameter("BUCKET_ID", bucketId)
            .Parameter("PULL_TYPE", bucket.RequireBoxExpediting ? "EXP" : null)
            .Parameter("PITCH_TYPE", bucket.QuickPitch ? "QUICK" : null)
            .Parameter("PITCH_LIMIT", bucket.PitchLimit)
            .Parameter("BUCKET_COMMENT", bucket.BucketComment);

            binder.OutParameter("NAME_OUT", p => bucket.BucketName          = p)
            .OutParameter("BUCKET_COMMENT_OUT", p => bucket.BucketComment   = p)
            .OutParameter("PITCH_LIMIT_OUT", p => bucket.PitchLimit         = p ?? 0) //TODO
            .OutParameter("PULL_TYPE_OUT", p => bucket.RequireBoxExpediting = p == "EXP")
            .OutParameter("PITCH_TYPE_OUT", p => bucket.QuickPitch          = p == "QUICK")
            .OutParameter("PITCH_IA_ID_OUT", p => bucket.PitchAreaId        = p)
            .OutParameter("PULL_CARTON_AREA_OUT", p => bucket.PullAreaId    = p)
            .OutParameter("FREEZE_OUT", p => bucket.IsFrozen = p == "Y");


            int rows = _db.ExecuteDml(QUERY, binder);

            if (rows == 0)
            {
                // Invalid bucket id
                throw new ArgumentOutOfRangeException("bucketId", "Could not update pick wave " + bucketId.ToString());
            }

            return(bucket);
        }