Ejemplo n.º 1
0
        public CertificateBatch Map(CertificateBatch batch,
                                    Certificate certificate = null,
                                    Premise premise         = null,
                                    Premise mailingPremise  = null,
                                    Comment comment         = null,
                                    Menu menu = null)
        {
            if (!_batchCache.TryGetValue(batch.ID, out CertificateBatch result))
            {
                _batchCache[batch.ID] = batch;
                result = batch;
            }

            Certificate outCertificate = null;

            if ((certificate?.ID ?? 0) > 0 &&
                !_certificateCache.TryGetValue(certificate.ID, out outCertificate))
            {
                outCertificate = certificate;
                _certificateCache[certificate.ID] = certificate;

                certificate.Premise        = premise;
                certificate.MailingPremise = mailingPremise;

                if (result.Certificates == null)
                {
                    result.Certificates = new List <Certificate>();
                }
                result.Certificates.Add(certificate);
            }

            if ((comment?.ID ?? 0) > 0 &&
                !_commentCache.ContainsKey(comment.ID))
            {
                _commentCache[comment.ID] = comment;

                if (result.Comments == null)
                {
                    result.Comments = new List <Comment>();
                }
                result.Comments.Add(comment);
            }

            if ((menu?.ID ?? 0) > 0 &&
                !_menuCache.ContainsKey(menu.ID))
            {
                _menuCache[menu.ID] = menu;

                if (outCertificate.Menus == null)
                {
                    outCertificate.Menus = new List <Menu>();
                }
                outCertificate.Menus.Add(menu);
            }

            return(batch);
        }
Ejemplo n.º 2
0
        public async Task <long> InsertCertificateBatch(CertificateBatch batch)
        {
            var param = new DynamicParameters();

            param.Add("@Code", batch.Code);
            param.Add("@Description", batch.Description);
            param.Add("@Template", batch.Template);

            param.Add("@ID", dbType: DbType.Int64, direction: ParameterDirection.Output);

            await SqlMapper.QueryAsync <CertificateBatch>(_unitOfWork.Connection,
                                                          "InsertCertificateBatch",
                                                          param,
                                                          commandType : CommandType.StoredProcedure,
                                                          transaction : _unitOfWork.Transaction);

            return(param.Get <long>("@ID"));
        }