示例#1
0
        public bool UpdateField(ErrorLogDataAccess.DataClasses.Field FieldObj)
        {
            using (TransactionScope scope1 = new TransactionScope())
            {
                try
                {
                    string formattedDate = DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss tt", CultureInfo.InvariantCulture);

                    var FieldCollection = mongoDatabaseRunTime.GetCollection <ErrorLogDataAccess.DataClasses.Field>("Field");


                    var filterObj = Builders <ErrorLogDataAccess.DataClasses.Field> .Filter.Eq("FieldCode", FieldObj.FieldCode);

                    var updateObj = Builders <ErrorLogDataAccess.DataClasses.Field> .Update
                                    .Set("FieldName", FieldObj.FieldName)
                                    .Set("FieldDescription", FieldObj.FieldDescription)
                                    .Set("IsActive", FieldObj.IsActive)
                                    .Set("LastUpdatedDate", formattedDate)
                                    .CurrentDate("lastModified");


                    FieldCollection.UpdateOne(filterObj, updateObj);


                    scope1.Complete();

                    return(true);
                }
                catch (Exception ex)
                {
                    scope1.Dispose();
                    throw;
                }
            }
        }
示例#2
0
        //save using a 'Field' type variable
        public bool SaveField(ErrorLogDataAccess.DataClasses.Field FieldObj, int userId = 1)
        {
            using (TransactionScope scope1 = new TransactionScope())
            {
                try
                {
                    string formattedDate = DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss tt", CultureInfo.InvariantCulture);

                    var FieldCollection = mongoDatabaseRunTime.GetCollection <ErrorLogDataAccess.DataClasses.Field>("Field");

                    var FieldRow = new ErrorLogDataAccess.DataClasses.Field()
                    {
                        FieldId          = GetNewFieldID(),
                        FieldCode        = FieldObj.FieldCode,
                        FieldName        = FieldObj.FieldName,
                        FieldDescription = FieldObj.FieldDescription,
                        IsActive         = FieldObj.IsActive,
                        EntryDate        = formattedDate,
                        UserId           = 1
                    };

                    FieldCollection.InsertOne(FieldRow);

                    scope1.Complete();

                    return(true);
                }
                catch (Exception)
                {
                    scope1.Dispose();
                    throw;
                }
            }
        }