Exemplo n.º 1
0
        public override async Task <int> HandleCommand(InsertCaptionCommand request, CancellationToken cancellationToken)
        {
            var id = 0;

            using (var conn = DALHelper.GetConnection())
            {
                conn.Open();
                using (var trans = conn.BeginTransaction())
                {
                    try
                    {
                        request.Model.CreatedDate  = DateTime.Now;
                        request.Model.CreatedBy    = request.LoginSession.Id;
                        request.Model.ModifiedDate = DateTime.Now;
                        request.Model.ModifiedBy   = request.LoginSession.Id;

                        id = await captionRepository.AddAsync(request.Model);

                        if (request.Model.Languages != null && request.Model.Languages.Count > 0)
                        {
                            foreach (var clang in request.Model.Languages)
                            {
                                if (clang.Id <= 0 && !string.IsNullOrWhiteSpace(clang.Caption))
                                {
                                    clang.CaptionId = id;
                                    await captionLanguageRepository.AddAsync(clang);
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                    finally
                    {
                        if (id > 0)
                        {
                            trans.Commit();
                        }
                        else
                        {
                            try { trans.Rollback(); } catch { }
                        }
                    }
                }
            }

            return(id);
        }