示例#1
0
        public Payload<Comment> Comment(Comment obj)
        {
            // create payload
            var payload = new Payload<Comment>();

            // Prep obj
            obj.Created = DateTime.Now;

            // validate
            var rules = new ValidationRules();
            rules.Validate(obj);

            // check if valid
            if (rules.IsValid)
            {
                // db save
                using (var queries = new CommentQueries())
                {
                    queries.Save(ref obj);
                }

                payload.Data = obj;
            }

            // todo: next steps in workflow

            // return payload
            return payload;
        }
示例#2
0
        public void Save(ref Comment obj)
        {
            if (obj != null)
            {
                if (obj.Id == 0)
                {
                    // Add to collection
                    context.Comments.Add(obj);
                }
                else
                {
                    // Map from original record
                    LoadOriginalFromDbAndMap(ref obj);

                    // Attach to collection
                    context.Comments.Attach(obj);
                    context.Entry(obj).State = System.Data.EntityState.Modified;
                }

                // Commit changes
                var utility = new DbUtilities();
                utility.SaveWithExpectedSuccess(context.SaveChanges());
            }
        }
示例#3
0
 /// <summary>
 /// Comment validation
 /// </summary>
 /// <param name="obj"></param>
 public void Validate(Comment obj)
 {
 }
示例#4
0
        private void LoadOriginalFromDbAndMap(ref Comment obj)
        {
            // Use utility for easier readability
            var utility = new DbUtilities();

            // Get original
            var original = Get(obj.Id);

            // Map if the value has changed
            original.ResourceId = utility.Map(original.ResourceId, obj.ResourceId);
            original.ContributorGuid = utility.Map(original.ContributorGuid, obj.ContributorGuid);
            original.Text = utility.Map(original.Text, obj.Text);

            // Set obj to new merged values (original)
            obj = original;
        }