示例#1
0
文件: Chirp.cs 项目: neiz/Chirpy
 internal Domain.Model.Chirp ToDomainChirp()
 {
     Domain.Model.Chirp domainChirp= new Domain.Model.Chirp
     {
         Id = this.Id,
         Value = this.Value
     };
     if (this.ChirpReplies != null)
     {
         //foreach (Data.Model.Chirp chirp in this.ChirpReplies)
         //{
         //    domainChirp.Replies.Add(chirp.ToDomainChirp());
         //}
     }
     foreach (string tag in Tags)
     {
         domainChirp.Tags.Add(new Domain.Model.ChirpTag { Tag = tag });
     }
     return domainChirp;
 }
        public long AddChirp(Domain.Model.Chirp chirp)
        {
            using (ChirpyRDataContext context =
                       new ChirpyRDataContext(_connectionName, _schemaName))
            {
                Data.Model.Chirp replyChirp =
                    chirp.InReplyTo != null?
                    context.Chirps.Find(chirp.InReplyTo.Id) :
                        null;

                Data.Model.ChirpyRUser chirpUser =
                    chirp.ChirpBy != null?
                    context.ChirpyRUsers.Find(chirp.ChirpBy.Id) :
                        null;

                Data.Model.Chirp newChirp = new Model.Chirp();
                newChirp.LoadFromDomainEntity(chirp);
                context.Entry <Data.Model.Chirp>(newChirp).State =
                    System.Data.EntityState.Added;
                context.SaveChanges();
                return(newChirp.Id);
            }
        }
 public long AddChirp(Domain.Model.Chirp newChirp)
 {
     return(_repository.AddChirp(newChirp));
 }