Ejemplo n.º 1
0
        public object Update(object entity)
        {
            MEResponse resp   = (MEResponse)entity;
            bool       result = false;

            try
            {
                using (ProgramMongoContext ctx = new ProgramMongoContext(_dbName))
                {
                    var q = MB.Query <MEResponse> .EQ(b => b.Id, resp.Id);

                    var uv = new List <MB.UpdateBuilder>();
                    uv.Add(MB.Update.Set(MEResponse.NextStepIdProperty, resp.NextStepId));
                    uv.Add(MB.Update.Set(MEResponse.StepIdProperty, resp.StepId));
                    uv.Add(MB.Update.Set(MEResponse.NominalProperty, resp.Nominal));
                    uv.Add(MB.Update.Set(MEResponse.RequiredProperty, resp.Required));
                    uv.Add(MB.Update.Set(MEResponse.DeleteFlagProperty, false));
                    uv.Add(MB.Update.Set(MEResponse.SelectedProperty, resp.Selected));

                    uv.Add(MB.Update.Set(MEResponse.LastUpdatedOnProperty, DateTime.UtcNow));
                    uv.Add(MB.Update.Set(MEResponse.UpdatedByProperty, ObjectId.Parse(this.UserId)));

                    if (resp.Order != 0)
                    {
                        uv.Add(MB.Update.Set(MEResponse.OrderProperty, resp.Order));
                    }
                    if (resp.Text != null)
                    {
                        uv.Add(MB.Update.Set(MEResponse.TextProperty, resp.Text));
                    }
                    if (resp.Value != null)
                    {
                        uv.Add(MB.Update.Set(MEResponse.ValueProperty, resp.Value));
                    }
                    if (resp.Spawn != null)
                    {
                        uv.Add(MB.Update.SetWrapped <List <SpawnElement> >(MEResponse.SpawnElementProperty, resp.Spawn));
                    }

                    IMongoUpdate       update = MB.Update.Combine(uv);
                    WriteConcernResult res    = ctx.Responses.Collection.Update(q, update);
                    if (res.Ok)
                    {
                        result = true;
                        AuditHelper.LogDataAudit(this.UserId,
                                                 MongoCollectionName.Response.ToString(),
                                                 resp.Id.ToString(),
                                                 Common.DataAuditType.Update,
                                                 "");
                    }
                }
                return(result as object);
            }
            catch (Exception ex)
            {
                throw new Exception("DD:ResponseRepository:Update()::" + ex.Message, ex.InnerException);
            }
        }
Ejemplo n.º 2
0
        public object Insert(object newEntity)
        {
            try
            {
                ResponseDetail rs  = (ResponseDetail)newEntity;
                MEResponse     mer = new MEResponse(this.UserId)
                {
                    Id            = ObjectId.Parse(rs.Id),
                    NextStepId    = ObjectId.Parse(rs.NextStepId),
                    Nominal       = rs.Nominal,
                    Order         = rs.Order,
                    Required      = rs.Required,
                    Spawn         = DTOUtils.GetSpawnElements(rs.SpawnElement),
                    StepId        = ObjectId.Parse(rs.StepId),
                    Text          = rs.Text,
                    Value         = rs.Value,
                    DeleteFlag    = true,
                    LastUpdatedOn = DateTime.UtcNow,
                    Version       = 1.0,
                    UpdatedBy     = ObjectId.Parse(this.UserId)
                };

                bool res = false;

                using (ProgramMongoContext ctx = new ProgramMongoContext(_dbName))
                {
                    ctx.Responses.Collection.Insert(mer);

                    AuditHelper.LogDataAudit(this.UserId,
                                             MongoCollectionName.Response.ToString(),
                                             mer.Id.ToString(),
                                             Common.DataAuditType.Insert,
                                             "");

                    res = true;
                }
                return(res as object);
            }
            catch (Exception ex)
            {
                throw new Exception("DD:ResponseRepository:Insert()::" + ex.Message, ex.InnerException);
            }
        }
Ejemplo n.º 3
0
        public object FindByID(string entityID)
        {
            MEResponse response = null;

            try
            {
                using (ProgramMongoContext ctx = new ProgramMongoContext(_dbName))
                {
                    var findcp = MB.Query <MEResponse> .EQ(b => b.Id, ObjectId.Parse(entityID));

                    response = ctx.Responses.Collection.Find(findcp).FirstOrDefault();
                }

                return(response);
            }
            catch (Exception ex)
            {
                throw new Exception("DD:ResponseRepository:FindById()::" + ex.Message, ex.InnerException);
            }
        }